From d0b3ed4af5f07ff404f9da0972236be1e796137b Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Fri, 20 May 2022 10:50:59 -0700 Subject: [PATCH 1/7] Expose StoreContext in public API --- CHANGELOG.md | 3 +++ src/init.lua | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bc9ea2..ba0230a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # RoactRodux Changelog # Unreleased Changes +## 0.5.1 (2022-05-20) +* Expose StoreContext in public API (for use by hooks) ([#56](https://github.com/Roblox/roact-rodux/pull/56)) + ## 0.5.0 (2021-12-06) * Move store connection back to didMount to align more closely with ReactRedux and Roact api. * Conditionally update child mappedProps on didMount if the mappedStoreState has changed between init and mount. This should prevent components from receiving stale rodux state. diff --git a/src/init.lua b/src/init.lua index ca867ee..387d5df 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1,8 +1,10 @@ local StoreProvider = require(script.StoreProvider) +local StoreContext = require(script.StoreContext) local connect = require(script.connect) return { StoreProvider = StoreProvider, + StoreContext = StoreContext, connect = connect, UNSTABLE_connect2 = connect, } From 7264e73c3453f3491be4c04b24d6f0d9792c14d6 Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Fri, 20 May 2022 12:51:22 -0700 Subject: [PATCH 2/7] Version --- rotriever.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rotriever.toml b/rotriever.toml index 068c800..ab3e26e 100644 --- a/rotriever.toml +++ b/rotriever.toml @@ -3,7 +3,7 @@ name = "RoactRodux" author = "Roblox" license = "Apache-2.0" content_root = "src" -version = "0.5.0" +version = "0.5.1" files = ["*", "!*.spec.lua"] [dependencies] From 26e2bc8710df17ac9b16ad54b292ec127a0adff3 Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Mon, 7 Oct 2024 18:05:26 -0700 Subject: [PATCH 3/7] Make table form of mapDispatchToProps work with callable table actionCreators --- src/connect.lua | 24 ++++++++++++++++-------- src/connect.spec.lua | 6 ++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/connect.lua b/src/connect.lua index 1b467b8..ad6abd7 100644 --- a/src/connect.lua +++ b/src/connect.lua @@ -32,6 +32,14 @@ local function noop() return nil end +--[[ + Returns `true` if the value can be called i.e. you can write `value(...)`. +]] +local function isCallable(value: any): boolean + return type(value) == "function" or + (type(value) == "table" and getmetatable(value) and getmetatable(value).__call ~= nil) or false +end + --[[ The stateUpdater accepts props when they update and computes the complete set of props that should be passed to the wrapped component. @@ -77,7 +85,7 @@ local function connect? ) if mapStateToPropsOrThunk ~= nil then - assert(typeof(mapStateToPropsOrThunk) == "function", "mapStateToProps must be a function or nil!") + assert(isCallable(mapStateToPropsOrThunk), "mapStateToProps must be a function or nil!") else mapStateToPropsOrThunk = noop end @@ -142,7 +150,7 @@ local function connect)( + (dispatch :: any) :: ThunkfulDispatchProp + ) + elseif mapDispatchType == "table" then mappedStoreDispatch = {} for key, actionCreator in pairs(mapDispatchToProps :: ActionCreatorMap) do - assert(typeof(actionCreator) == "function", "mapDispatchToProps must contain function values") + assert(isCallable(actionCreator), "mapDispatchToProps must contain function values") mappedStoreDispatch[key] = function(...) dispatch(actionCreator(...)) end end - elseif mapDispatchType == "function" then - mappedStoreDispatch = (mapDispatchToProps :: MapDispatchToProps)( - (dispatch :: any) :: ThunkfulDispatchProp - ) end local stateUpdater = makeStateUpdater(self.store) diff --git a/src/connect.spec.lua b/src/connect.spec.lua index e0c1628..ee0fb6d 100644 --- a/src/connect.spec.lua +++ b/src/connect.spec.lua @@ -53,6 +53,12 @@ return function() }) end) + it("should accept action creators that are callable tables", function() + connect(nil, { + foo = Rodux.makeActionCreator("Foo", function() end), + }) + end) + it("should throw if not passed a component", function() local selector = function(store) return {} From 7adc822b3f5910faec30f041aa2fd035d1bdfd24 Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Mon, 7 Oct 2024 18:09:09 -0700 Subject: [PATCH 4/7] Update changelog, bump version --- CHANGELOG.md | 2 ++ rotriever.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0230a..d791476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # RoactRodux Changelog # Unreleased Changes +* Update function type checks to account for callable tables (like those returned by Rodux.makeActionCreator). + ## 0.5.1 (2022-05-20) * Expose StoreContext in public API (for use by hooks) ([#56](https://github.com/Roblox/roact-rodux/pull/56)) diff --git a/rotriever.toml b/rotriever.toml index f6bcc9d..dd9300c 100644 --- a/rotriever.toml +++ b/rotriever.toml @@ -3,7 +3,7 @@ name = "RoactRodux" authors = ["Roblox"] license = "Apache-2.0" content_root = "src" -version = "0.5.1" +version = "0.5.2" files = ["*", "!*.spec.lua"] [dependencies] From 969d481f8e1b4721381f164fe9553c520030d553 Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Mon, 7 Oct 2024 21:07:06 -0700 Subject: [PATCH 5/7] Update to latest luau-lsp. Current version is no longer found --- foreman.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foreman.toml b/foreman.toml index 014faff..d7778b8 100644 --- a/foreman.toml +++ b/foreman.toml @@ -2,4 +2,4 @@ rojo = { source = "rojo-rbx/rojo", version = "=7.2.1" } selene = { source = "Kampfkarren/selene", version = "=0.21.1" } stylua = { source = "JohnnyMorganz/StyLua", version = "=0.15.1" } -luau-lsp = { source = "JohnnyMorganz/luau-lsp", version = "=1.8.1" } +luau-lsp = { source = "JohnnyMorganz/luau-lsp", version = "=1.33.1" } From ffde1e4b670dd6241718ca71f8f75f7b44f7d5a9 Mon Sep 17 00:00:00 2001 From: Tony Cuadra Date: Mon, 7 Oct 2024 21:23:43 -0700 Subject: [PATCH 6/7] Fix type error --- src/connect.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connect.lua b/src/connect.lua index ad6abd7..aed2a60 100644 --- a/src/connect.lua +++ b/src/connect.lua @@ -151,7 +151,7 @@ local function connect Date: Mon, 7 Oct 2024 21:27:07 -0700 Subject: [PATCH 7/7] stylua --- src/connect.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/connect.lua b/src/connect.lua index aed2a60..33803d8 100644 --- a/src/connect.lua +++ b/src/connect.lua @@ -36,8 +36,9 @@ end Returns `true` if the value can be called i.e. you can write `value(...)`. ]] local function isCallable(value: any): boolean - return type(value) == "function" or - (type(value) == "table" and getmetatable(value) and getmetatable(value).__call ~= nil) or false + return type(value) == "function" + or (type(value) == "table" and getmetatable(value) and getmetatable(value).__call ~= nil) + or false end --[[