Skip to content

Commit 87a7677

Browse files
committed
!feat: connect parameter defaults to true
1 parent 0810215 commit 87a7677

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

spec/slot_spec.lua

+16-3
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,35 @@ describe("Awesome-slot", function()
4141

4242
slot.remove(s)
4343

44+
assert.is_false(s.connected) -- remove should also invoke disconnect_signal
4445
assert.is_nil(slot.get_slot(s))
4546
end)
4647

47-
it("should connect slot (from constructor parameters)", function()
48+
it("should automatically connect slot", function()
4849
local target = new_target()
4950

5051
local s = slot {
5152
target = target,
5253
signal = "signal",
5354
slot = function() end,
54-
slot_params = { key = "value" },
55-
connect = true,
5655
}
5756

5857
assert.is_true(s.connected)
5958
end)
6059

60+
it("should prevent slot connection with parameter", function()
61+
local target = new_target()
62+
63+
local s = slot {
64+
target = target,
65+
signal = "signal",
66+
slot = function() end,
67+
connect = false,
68+
}
69+
70+
assert.is_false(s.connected)
71+
end)
72+
6173
it("should connect signal", function()
6274
local target = new_target()
6375

@@ -66,6 +78,7 @@ describe("Awesome-slot", function()
6678
signal = "signal",
6779
slot = function() end,
6880
slot_params = { key = "value" },
81+
connect = false,
6982
}
7083

7184
slot.connect(s)

src/awesome-slot/init.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ end
110110
-- @tparam table params.slot_params The parameters to pass to the callback
111111
-- function. (The signal will invoke the callback function with this table as
112112
-- parameter)
113-
-- @tparam[opt=false] boolean params.connect Connect the slot now.
113+
-- @tparam[opt=true] boolean params.connect Connect the slot now.
114114
-- @treturn Slot The created Slot instance.
115115
-- @constructorfct awesome_slot
116116
function awesome_slot.create(params)
@@ -127,7 +127,7 @@ function awesome_slot.create(params)
127127
-- Insert the new slot into the slots list
128128
awesome_slot._private.registered_slots[slot.id] = slot
129129

130-
if params.connect then
130+
if params.connect == nil or params.connect then
131131
awesome_slot.connect(slot)
132132
end
133133

@@ -142,7 +142,7 @@ function awesome_slot.remove(slot)
142142
local s = awesome_slot.get_slot(slot)
143143

144144
if s.connected then
145-
awesome_slot.disconnect_slot(s)
145+
awesome_slot.disconnect(s)
146146
end
147147

148148
awesome_slot._private.registered_slots[s.id] = nil

0 commit comments

Comments
 (0)