mirror of
https://github.com/kikito/beholder.lua.git
synced 2024-12-16 00:34:21 +00:00
added function beholder.stopPropagation
Event can now be stopped from propagating further on. Usage/Example: https://gist.github.com/LukeMS/5e6bc467a420ee2cc7544f690c3c4fae
This commit is contained in:
parent
9f1a31eb51
commit
a0c0f794dc
@ -49,8 +49,10 @@ end
|
|||||||
local function invokeNodeCallbacks(self, params)
|
local function invokeNodeCallbacks(self, params)
|
||||||
-- copy the hash into an array, for safety (self-erasures)
|
-- copy the hash into an array, for safety (self-erasures)
|
||||||
local callbacks, count = hash2array(self.callbacks)
|
local callbacks, count = hash2array(self.callbacks)
|
||||||
|
self.stop_propagation = false
|
||||||
for i=1,#callbacks do
|
for i=1,#callbacks do
|
||||||
callbacks[i](unpack(params))
|
callbacks[i](unpack(params))
|
||||||
|
if self.stop_propagation then break end
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
@ -137,6 +139,13 @@ function beholder.observe(...)
|
|||||||
return addIdToCurrentGroup(addCallbackToNode(node, callback))
|
return addIdToCurrentGroup(addCallbackToNode(node, callback))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- When called the event will stop and no longer propagate
|
||||||
|
-- (i.e. loop at invokeNodeCallbacks will break)
|
||||||
|
function beholder.stopPropagation(id)
|
||||||
|
local node = findNodeById(id)
|
||||||
|
node.stop_propagation = true
|
||||||
|
end
|
||||||
|
|
||||||
function beholder.stopObserving(id)
|
function beholder.stopObserving(id)
|
||||||
local node = findNodeById(id)
|
local node = findNodeById(id)
|
||||||
if node then removeCallbackFromNode(node, id) end
|
if node then removeCallbackFromNode(node, id) end
|
||||||
|
Loading…
Reference in New Issue
Block a user