From 87a767705d22821279dd3d1e8aec22318c2a9bba Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 28 Nov 2024 00:36:56 +0100 Subject: [PATCH] !feat: `connect` parameter defaults to `true` --- spec/slot_spec.lua | 19 ++++++++++++++++--- src/awesome-slot/init.lua | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/spec/slot_spec.lua b/spec/slot_spec.lua index 2b54a75..49e8997 100644 --- a/spec/slot_spec.lua +++ b/spec/slot_spec.lua @@ -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) diff --git a/src/awesome-slot/init.lua b/src/awesome-slot/init.lua index 52f5fdf..41cfff3 100644 --- a/src/awesome-slot/init.lua +++ b/src/awesome-slot/init.lua @@ -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