Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the initialState argument of createReducer is nil, then its actionHandlers are never called. #39

Closed
Mduro opened this issue Dec 2, 2018 · 2 comments

Comments

@Mduro
Copy link

Mduro commented Dec 2, 2018

Consider the following code:

local Rodux = require(workspace.Rodux)

local testReducer = Rodux.createReducer(
	nil,
	{
		TestStringSet = function(state, action)
			print("TestStringSet was called")
			return action.string
		end
	}
)

local reducer = Rodux.combineReducers(
	{
		testString = testReducer
	}
)

local SetTestString = function(str)
	return {
		type = "TestStringSet",
		string = str
	}
end

local store = Rodux.Store.new(reducer)

store:dispatch(SetTestString("foo"))
print(store:getState().testString)

When I run this, only nil is printed. TestStringSet was called also wasn't printed, which means that the handler wasn't called.

When I change the initialState argument of createReducer from nil to any non-nil value ({} for example"), TestStringSet was called and foo are printed, in that order.

@LPGhatguy
Copy link
Contributor

I stared at this for awhile, since it didn't make sense to me why this would happen!

This was fixed in #33, which probably wasn't in the last binary release for Rodux. You should be able to pull in the latest Git master via Rojo, but I'll go ahead and publish a new release as well.

@Mduro
Copy link
Author

Mduro commented Dec 4, 2018

Right, my bad. Should have occurred to me to test on the latest version of the code. Thanks for the new release!

@Mduro Mduro closed this as completed Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants