!feat: `connect` parameter defaults to `true`
This commit is contained in:
parent
08102153b1
commit
87a767705d
|
@ -41,23 +41,35 @@ describe("Awesome-slot", function()
|
|||
|
||||
slot.remove(s)
|
||||
|
||||
assert.is_false(s.connected) -- remove should also invoke disconnect_signal
|
||||
assert.is_nil(slot.get_slot(s))
|
||||
end)
|
||||
|
||||
it("should connect slot (from constructor parameters)", function()
|
||||
it("should automatically connect slot", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
connect = true,
|
||||
}
|
||||
|
||||
assert.is_true(s.connected)
|
||||
end)
|
||||
|
||||
it("should prevent slot connection with parameter", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
connect = false,
|
||||
}
|
||||
|
||||
assert.is_false(s.connected)
|
||||
end)
|
||||
|
||||
it("should connect signal", function()
|
||||
local target = new_target()
|
||||
|
||||
|
@ -66,6 +78,7 @@ describe("Awesome-slot", function()
|
|||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
connect = false,
|
||||
}
|
||||
|
||||
slot.connect(s)
|
||||
|
|
|
@ -110,7 +110,7 @@ end
|
|||
-- @tparam table params.slot_params The parameters to pass to the callback
|
||||
-- function. (The signal will invoke the callback function with this table as
|
||||
-- parameter)
|
||||
-- @tparam[opt=false] boolean params.connect Connect the slot now.
|
||||
-- @tparam[opt=true] boolean params.connect Connect the slot now.
|
||||
-- @treturn Slot The created Slot instance.
|
||||
-- @constructorfct awesome_slot
|
||||
function awesome_slot.create(params)
|
||||
|
@ -127,7 +127,7 @@ function awesome_slot.create(params)
|
|||
-- Insert the new slot into the slots list
|
||||
awesome_slot._private.registered_slots[slot.id] = slot
|
||||
|
||||
if params.connect then
|
||||
if params.connect == nil or params.connect then
|
||||
awesome_slot.connect(slot)
|
||||
end
|
||||
|
||||
|
@ -142,7 +142,7 @@ function awesome_slot.remove(slot)
|
|||
local s = awesome_slot.get_slot(slot)
|
||||
|
||||
if s.connected then
|
||||
awesome_slot.disconnect_slot(s)
|
||||
awesome_slot.disconnect(s)
|
||||
end
|
||||
|
||||
awesome_slot._private.registered_slots[s.id] = nil
|
||||
|
|
Loading…
Reference in New Issue