feat(object): implement is(_weak)_signal_connected
This commit is contained in:
parent
d536a5062c
commit
cd8df4f1bd
|
@ -60,6 +60,21 @@ function object:connect_signal(name, func)
|
|||
sig.strong[func] = true
|
||||
end
|
||||
|
||||
--- Check if the callback is connected to the signal.
|
||||
--
|
||||
-- @tparam string name The name of the signal.
|
||||
-- @tparam function func The callback to check if connected.
|
||||
-- @treturn boolean Whether the signal is connected.
|
||||
-- @method is_signal_connected
|
||||
function object:is_signal_connected(name, func)
|
||||
assert(
|
||||
type(func) == "function",
|
||||
"callback must be a function, got: " .. type(func)
|
||||
)
|
||||
local sig = find_signal(self, name)
|
||||
return not not (sig and sig.strong[func])
|
||||
end
|
||||
|
||||
-- Register a global signal receiver.
|
||||
function object:_connect_everything(callback)
|
||||
table.insert(self._global_receivers, callback)
|
||||
|
@ -114,6 +129,21 @@ function object:weak_connect_signal(name, func)
|
|||
sig.weak[func] = make_the_gc_obey(func)
|
||||
end
|
||||
|
||||
--- Check if the callback is weakly connected to the signal.
|
||||
--
|
||||
-- @tparam string name The name of the signal.
|
||||
-- @tparam function func The callback to check if connected.
|
||||
-- @treturn boolean Whether the signal is connected.
|
||||
-- @method is_weak_signal_connected
|
||||
function object:is_weak_signal_connected(name, func)
|
||||
assert(
|
||||
type(func) == "function",
|
||||
"callback must be a function, got: " .. type(func)
|
||||
)
|
||||
local sig = find_signal(self, name)
|
||||
return not not (sig and sig.weak[func])
|
||||
end
|
||||
|
||||
--- Disonnect from a signal.
|
||||
-- @tparam string name The name of the signal.
|
||||
-- @tparam function func The callback that should be disconnected.
|
||||
|
|
|
@ -185,6 +185,20 @@ describe("gears.object", function()
|
|||
object{enable_auto_signals=true, enable_properties=false}
|
||||
end)
|
||||
end)
|
||||
|
||||
it("is_signal_connected", function()
|
||||
local cb = function()end
|
||||
assert.is_false(obj:is_signal_connected("signal", cb))
|
||||
obj:connect_signal("signal", cb)
|
||||
assert.is_true(obj:is_signal_connected("signal", cb))
|
||||
end)
|
||||
|
||||
it("is_weak_signal_connected", function()
|
||||
local cb = function()end
|
||||
assert.is_false(obj:is_weak_signal_connected("signal", cb))
|
||||
obj:weak_connect_signal("signal", cb)
|
||||
assert.is_true(obj:is_weak_signal_connected("signal", cb))
|
||||
end)
|
||||
end)
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue