From e9a3d1a11354fd873aa21fe721ffbf5036905c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Garc=C3=ADa?= Date: Wed, 26 Oct 2011 00:31:33 +0200 Subject: [PATCH] added params to trigger --- beholder.lua | 5 +++-- spec/acceptance.lua | 15 +++++++++++++++ spec/unit.lua | 12 ++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/beholder.lua b/beholder.lua index c0c65f6..38b45b0 100644 --- a/beholder.lua +++ b/beholder.lua @@ -25,12 +25,13 @@ end function beholder:stopObserving(id) local event = self._ids[id] self._actions[event][id] = nil + self._ids[id]=nil end -function beholder:trigger(event) +function beholder:trigger(event,...) local actions = self._actions[event] or {} for _,action in pairs(actions) do - action() + action(...) end end diff --git a/spec/acceptance.lua b/spec/acceptance.lua index 9574371..3d8a8ea 100644 --- a/spec/acceptance.lua +++ b/spec/acceptance.lua @@ -53,4 +53,19 @@ describe("Acceptance", function() 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) diff --git a/spec/unit.lua b/spec/unit.lua index b9571af..e550b69 100644 --- a/spec/unit.lua +++ b/spec/unit.lua @@ -50,6 +50,18 @@ describe("Unit", function() assert_equal(counter2, 2) 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)