Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create event listener table on fire if it doesn't exist #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ end

-- Sends event to current node only
function node:fire(event_type, ...)
self.listeners[event_type] = self.listeners[event_type] or {}
for _, listener in ipairs(self.listeners[event_type]) do
local stopLocal, stopGlobal = listener(...)
if stopGlobal then
Expand Down
11 changes: 11 additions & 0 deletions spec/event_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe("event listeners", function()
assert.is_equal(test_obj.test_value, 3)
end)

it("can be emitted without listener", function()
local node = scene.node()
node:emit("test")
end)

it("can be broadcasted", function()
local node1 = scene.node{id="1"}
local node2 = scene.node{id="2"}
Expand All @@ -71,4 +76,10 @@ describe("event listeners", function()
assert.is_equal(test_obj.received[2], node2)
assert.is_equal(test_obj.received[3], node3)
end)

it("can be broadcasted without listener", function()
local node = scene.node({id="1"})
node:broadcast("test")
end)

end)