feat(object): merge both is_signal_connected
This commit is contained in:
parent
40ec479a95
commit
2a1694695e
|
@ -62,6 +62,8 @@ end
|
|||
|
||||
--- Check if the callback is connected to the signal.
|
||||
--
|
||||
-- This function check both kind of signal connection (strong and weak).
|
||||
--
|
||||
-- @tparam string name The name of the signal.
|
||||
-- @tparam function func The callback to check if connected.
|
||||
-- @treturn boolean Whether the signal is connected.
|
||||
|
@ -72,7 +74,7 @@ function object:is_signal_connected(name, func)
|
|||
"callback must be a function, got: " .. type(func)
|
||||
)
|
||||
local sig = find_signal(self, name)
|
||||
return not not (sig and sig.strong[func])
|
||||
return not not (sig and (sig.strong[func] or sig.weak[func]))
|
||||
end
|
||||
|
||||
-- Register a global signal receiver.
|
||||
|
@ -129,21 +131,6 @@ 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.
|
||||
|
|
|
@ -195,9 +195,9 @@ describe("gears.object", function()
|
|||
|
||||
it("is_weak_signal_connected", function()
|
||||
local cb = function()end
|
||||
assert.is_false(obj:is_weak_signal_connected("signal", cb))
|
||||
assert.is_false(obj:is_signal_connected("signal", cb))
|
||||
obj:weak_connect_signal("signal", cb)
|
||||
assert.is_true(obj:is_weak_signal_connected("signal", cb))
|
||||
assert.is_true(obj:is_signal_connected("signal", cb))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in New Issue