mirror of
https://github.com/kikito/beholder.lua.git
synced 2024-12-16 00:34:21 +00:00
added test and fix for undue hard reference storage
This commit is contained in:
parent
9ee88a6f4f
commit
71c1118039
@ -18,7 +18,8 @@ local Node = {
|
||||
}
|
||||
|
||||
function Node:new()
|
||||
return setmetatable( { callbacks = {}, children = {} }, { __index = Node } )
|
||||
local node = { callbacks = {}, children = setmetatable({}, {__mode="k"}) }
|
||||
return setmetatable( node, { __index = Node } )
|
||||
end
|
||||
|
||||
function Node:findById(id)
|
||||
|
@ -45,6 +45,17 @@ describe("Unit", function()
|
||||
it("throws an error if called without at least one parameter", function()
|
||||
assert_error(function() beholder:observe() end)
|
||||
end)
|
||||
|
||||
it("does not store hard references to variables", function()
|
||||
local counter = 0
|
||||
local x = {}
|
||||
beholder:observe(x, function() counter = counter + 1 end)
|
||||
beholder:triggerAll()
|
||||
x = nil
|
||||
collectgarbage("collect")
|
||||
beholder:triggerAll()
|
||||
assert_equal(1, counter)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe(":stopObserving", function()
|
||||
|
Loading…
Reference in New Issue
Block a user