Skip to content

Commit

Permalink
!feat: connect parameter defaults to true
Browse files Browse the repository at this point in the history
  • Loading branch information
Aire-One committed Nov 27, 2024
1 parent 0810215 commit 87a7677
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 16 additions & 3 deletions spec/slot_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -66,6 +78,7 @@ describe("Awesome-slot", function()
signal = "signal",
slot = function() end,
slot_params = { key = "value" },
connect = false,
}

slot.connect(s)
Expand Down
6 changes: 3 additions & 3 deletions src/awesome-slot/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 87a7677

Please sign in to comment.