Skip to content

Commit

Permalink
Merge pull request #99 from pturner-roblox/cherry-pick-3.3.0
Browse files Browse the repository at this point in the history
Bump to 3.3.0 to take performance improvement in Signal
  • Loading branch information
jkelaty-rbx authored Nov 20, 2024
2 parents 7ee2311 + 2964e52 commit 909db6e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 38 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/clabot.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased Changes

## 3.3.0 (2024-11-19)
* Add flag around change to only call traceback() in connection listeners in `__DEV__` ([#98](https://github.com/Roblox/rodux/pull/98))
* Only call traceback() in connection listeners in `__DEV__` ([#78](https://github.com/Roblox/rodux/pull/78))

## 3.2.0 (2023-11-17)
* Add makeThunkMiddleware to inject custom argument ([#94](https://github.com/Roblox/rodux/pull/94)).

Expand Down
2 changes: 1 addition & 1 deletion rotriever.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "Rodux"
authors = ["Roblox"]
license = "Apache-2.0"
content_root = "src"
version = "3.2.0"
version = "3.3.0"
45 changes: 29 additions & 16 deletions src/Signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Handlers are fired in order, and (dis)connections are properly handled when
executing an event.
]]
local __DEV__ = _G.__DEV__

local _, FFlagRoduxRemoveConnectTraceback = xpcall(function()
return game:DefineFastFlag("RoduxRemoveConnectTraceback", false)
end, function()
return true
end)

local function immutableAppend(list, ...)
local new = {}
local len = #list
Expand Down Expand Up @@ -38,7 +46,7 @@ Signal.__index = Signal
function Signal.new(store)
local self = {
_listeners = {},
_store = store
_store = store,
}

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

if self._store and self._store._isDispatching then
error(
'You may not call store.changed:connect() while the reducer is executing. ' ..
'If you would like to be notified after the store has been updated, subscribe from a ' ..
'component and invoke store:getState() in the callback to access the latest state. '
"You may not call store.changed:connect() while the reducer is executing. "
.. "If you would like to be notified after the store has been updated, subscribe from a "
.. "component and invoke store:getState() in the callback to access the latest state. "
)
end

local listener = {
callback = callback,
disconnected = false,
connectTraceback = debug.traceback(),
disconnectTraceback = nil
connectTraceback = nil,
disconnectTraceback = nil,
}

if not FFlagRoduxRemoveConnectTraceback or __DEV__ then
listener.connectTraceback = debug.traceback()
end

self._listeners = immutableAppend(self._listeners, listener)

local function disconnect()
if listener.disconnected then
error((
"Listener connected at: \n%s\n" ..
"was already disconnected at: \n%s\n"
):format(
tostring(listener.connectTraceback),
tostring(listener.disconnectTraceback)
))
error(
("Listener connected at: \n%s\n" .. "was already disconnected at: \n%s\n"):format(
tostring(listener.connectTraceback),
tostring(listener.disconnectTraceback)
)
)
end

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

if not FFlagRoduxRemoveConnectTraceback or __DEV__ then
listener.disconnectTraceback = debug.traceback()
end
listener.disconnected = true
listener.disconnectTraceback = debug.traceback()
self._listeners = immutableRemoveValue(self._listeners, listener)
end

return {
disconnect = disconnect
disconnect = disconnect,
}
end

Expand All @@ -101,4 +114,4 @@ function Signal:fire(...)
end
end

return Signal
return Signal

0 comments on commit 909db6e

Please sign in to comment.