Skip to content

Commit 57d46d3

Browse files
cherrypick: src/Signal.lua
1 parent 7ee2311 commit 57d46d3

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/Signal.lua

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Handlers are fired in order, and (dis)connections are properly handled when
55
executing an event.
66
]]
7+
local __DEV__ = _G.__DEV__
8+
9+
local _, FFlagRoduxRemoveConnectTraceback = xpcall(function()
10+
return game:DefineFastFlag("RoduxRemoveConnectTraceback", false)
11+
end, function()
12+
return true
13+
end)
14+
715
local function immutableAppend(list, ...)
816
local new = {}
917
local len = #list
@@ -35,10 +43,10 @@ local Signal = {}
3543

3644
Signal.__index = Signal
3745

38-
function Signal.new(store)
46+
function Signal.new(store: Store?)
3947
local self = {
4048
_listeners = {},
41-
_store = store
49+
_store = store,
4250
}
4351

4452
setmetatable(self, Signal)
@@ -53,43 +61,48 @@ function Signal:connect(callback)
5361

5462
if self._store and self._store._isDispatching then
5563
error(
56-
'You may not call store.changed:connect() while the reducer is executing. ' ..
57-
'If you would like to be notified after the store has been updated, subscribe from a ' ..
58-
'component and invoke store:getState() in the callback to access the latest state. '
64+
"You may not call store.changed:connect() while the reducer is executing. "
65+
.. "If you would like to be notified after the store has been updated, subscribe from a "
66+
.. "component and invoke store:getState() in the callback to access the latest state. "
5967
)
6068
end
6169

62-
local listener = {
70+
local listener: Listener = {
6371
callback = callback,
6472
disconnected = false,
65-
connectTraceback = debug.traceback(),
66-
disconnectTraceback = nil
73+
connectTraceback = nil,
74+
disconnectTraceback = nil,
6775
}
6876

77+
if not FFlagRoduxRemoveConnectTraceback or __DEV__ then
78+
listener.connectTraceback = debug.traceback()
79+
end
80+
6981
self._listeners = immutableAppend(self._listeners, listener)
7082

7183
local function disconnect()
7284
if listener.disconnected then
73-
error((
74-
"Listener connected at: \n%s\n" ..
75-
"was already disconnected at: \n%s\n"
76-
):format(
77-
tostring(listener.connectTraceback),
78-
tostring(listener.disconnectTraceback)
79-
))
85+
error(
86+
("Listener connected at: \n%s\n" .. "was already disconnected at: \n%s\n"):format(
87+
tostring(listener.connectTraceback),
88+
tostring(listener.disconnectTraceback)
89+
)
90+
)
8091
end
8192

8293
if self._store and self._store._isDispatching then
8394
error("You may not unsubscribe from a store listener while the reducer is executing.")
8495
end
8596

97+
if not FFlagRoduxRemoveConnectTraceback or __DEV__ then
98+
listener.disconnectTraceback = debug.traceback()
99+
end
86100
listener.disconnected = true
87-
listener.disconnectTraceback = debug.traceback()
88101
self._listeners = immutableRemoveValue(self._listeners, listener)
89102
end
90103

91104
return {
92-
disconnect = disconnect
105+
disconnect = disconnect,
93106
}
94107
end
95108

@@ -101,4 +114,4 @@ function Signal:fire(...)
101114
end
102115
end
103116

104-
return Signal
117+
return Signal

0 commit comments

Comments
 (0)