File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1010 * The middleware API changed in [#29](https://github.com/Roblox/rodux/pull/29) in a backwards-incompatible way!
1111 * Middleware now run left-to-right instead of right-to-left!
1212* Errors thrown in ` changed ` event now have correct stack traces ([ #27 ] ( https://github.com/Roblox/rodux/pull/27 ) )
13+ * Fixed ` createReducer ` having incorrect behavior with ` nil ` state values ([ #33 ] ( https://github.com/Roblox/rodux/pull/33 ) )
1314
1415## Public Release (December 13, 2017)
1516* Initial release!
Original file line number Diff line number Diff line change 11return function (initialState , handlers )
22 return function (state , action )
33 if state == nil then
4- return initialState
4+ state = initialState
55 end
66
77 local handler = handlers [action .type ]
Original file line number Diff line number Diff line change @@ -49,6 +49,33 @@ return function()
4949 expect (newState .b ).to .equal (0 )
5050 end )
5151
52+ it (" should still run action handlers if the state is nil" , function ()
53+ local callCount = 0
54+
55+ local reducer = createReducer (0 , {
56+ foo = function (state , action )
57+ callCount = callCount + 1
58+ return nil
59+ end
60+ })
61+
62+ expect (callCount ).to .equal (0 )
63+
64+ local newState = reducer (nil , {
65+ type = " foo" ,
66+ })
67+
68+ expect (callCount ).to .equal (1 )
69+ expect (newState ).to .equal (nil )
70+
71+ newState = reducer (newState , {
72+ type = " foo" ,
73+ })
74+
75+ expect (callCount ).to .equal (2 )
76+ expect (newState ).to .equal (nil )
77+ end )
78+
5279 it (" should return the same state if the action is not handled" , function ()
5380 local initialState = {
5481 a = 0 ,
You can’t perform that action at this time.
0 commit comments