diff --git a/beholder.lua b/beholder.lua index ada58c6..8d68593 100644 --- a/beholder.lua +++ b/beholder.lua @@ -49,8 +49,10 @@ end local function invokeNodeCallbacks(self, params) -- copy the hash into an array, for safety (self-erasures) local callbacks, count = hash2array(self.callbacks) + self.stop_propagation = false for i=1,#callbacks do callbacks[i](unpack(params)) + if self.stop_propagation then break end end return count end @@ -137,6 +139,13 @@ function beholder.observe(...) return addIdToCurrentGroup(addCallbackToNode(node, callback)) 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) local node = findNodeById(id) if node then removeCallbackFromNode(node, id) end