mirror of
https://github.com/kikito/beholder.lua.git
synced 2025-01-02 13:44:20 +00:00
added params to trigger
This commit is contained in:
parent
a061a2b898
commit
e9a3d1a113
@ -25,12 +25,13 @@ end
|
|||||||
function beholder:stopObserving(id)
|
function beholder:stopObserving(id)
|
||||||
local event = self._ids[id]
|
local event = self._ids[id]
|
||||||
self._actions[event][id] = nil
|
self._actions[event][id] = nil
|
||||||
|
self._ids[id]=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function beholder:trigger(event)
|
function beholder:trigger(event,...)
|
||||||
local actions = self._actions[event] or {}
|
local actions = self._actions[event] or {}
|
||||||
for _,action in pairs(actions) do
|
for _,action in pairs(actions) do
|
||||||
action()
|
action(...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,4 +53,19 @@ describe("Acceptance", function()
|
|||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test("callback parameters", function()
|
||||||
|
local counter = 0
|
||||||
|
|
||||||
|
beholder:observe("EVENT", function(x) counter = counter + x end)
|
||||||
|
|
||||||
|
beholder:trigger("EVENT", 1)
|
||||||
|
|
||||||
|
assert_equal(counter, 1)
|
||||||
|
|
||||||
|
beholder:trigger("EVENT", 5)
|
||||||
|
|
||||||
|
assert_equal(counter, 6)
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
@ -50,6 +50,18 @@ describe("Unit", function()
|
|||||||
assert_equal(counter2, 2)
|
assert_equal(counter2, 2)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("passes parameters to the actions", function()
|
||||||
|
local counter = 0
|
||||||
|
|
||||||
|
beholder:observe("EVENT", function(x) counter = counter + x end)
|
||||||
|
beholder:trigger("EVENT", 1)
|
||||||
|
|
||||||
|
assert_equal(counter, 1)
|
||||||
|
beholder:trigger("EVENT", 5)
|
||||||
|
|
||||||
|
assert_equal(counter, 6)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user