mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-04 13:23:54 -04:00
Fixed beforeEmit/afterEmit to handle recursive/nested emits;
This commit is contained in:
parent
9e0eeddea9
commit
b0fdb74d82
1 changed files with 8 additions and 2 deletions
|
@ -50,6 +50,8 @@ function World.new()
|
||||||
__systemLookup = {},
|
__systemLookup = {},
|
||||||
|
|
||||||
__isWorld = true,
|
__isWorld = true,
|
||||||
|
|
||||||
|
__ignoreEmits = false
|
||||||
}, World.__mt)
|
}, World.__mt)
|
||||||
|
|
||||||
-- Optimization: We deep copy the World class into our instance of a world.
|
-- Optimization: We deep copy the World class into our instance of a world.
|
||||||
|
@ -320,8 +322,10 @@ function World:emit(functionName, ...)
|
||||||
|
|
||||||
local listeners = self.__events[functionName]
|
local listeners = self.__events[functionName]
|
||||||
|
|
||||||
if Type.isCallable(self.beforeEmit) then
|
if not self.__ignoreEmits and Type.isCallable(self.beforeEmit) then
|
||||||
|
self.__ignoreEmits = true
|
||||||
self:beforeEmit(functionName, listeners, ...)
|
self:beforeEmit(functionName, listeners, ...)
|
||||||
|
self.__ignoreEmits = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if listeners then
|
if listeners then
|
||||||
|
@ -338,8 +342,10 @@ function World:emit(functionName, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Type.isCallable(self.afterEmit) then
|
if not self.__ignoreEmits and Type.isCallable(self.afterEmit) then
|
||||||
|
self.__ignoreEmits = true
|
||||||
self:afterEmit(functionName, listeners, ...)
|
self:afterEmit(functionName, listeners, ...)
|
||||||
|
self.__ignoreEmits = false
|
||||||
end
|
end
|
||||||
|
|
||||||
self.__emitSDepth = self.__emitSDepth - 1
|
self.__emitSDepth = self.__emitSDepth - 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue