Skip to content

Conversation

@thammi
Copy link

@thammi thammi commented Feb 20, 2020

An attempt to unify original reducers as defined by redux project (takes undefined as state argument, named Reducer) and the way reducers were defined here (does not take undefined as state argument, renamed to PreloadedReducer). Please note that a Reducer is always a PreloadedReducer as well. The types return the more general Reducer where possible.

It handles the following use cases I could come up with:

  • with initialState (removed null) returning a Reducer
  • with initialState (as before with null), returning a PreloadedReducer (Personally don't see much value in this one. Maybe add another option with intialState and Reducer as second argument?)
  • Reducer as first argument injecting the default state, returning a Reducer
  • only PreloadedReducers, returning a PreloadedReducer

I am not sure whether type inference is working the way it was before for all use cases. In my project (one Reducer and multiple PreloadedReducer) type inference worked as expected. I could build some additional test cases if required.

Naming of PreloadedReducer could be improved.

Related to pull request #38. Decided to redefine Reducer for now.

@thammi
Copy link
Author

thammi commented Mar 16, 2020

Is there any interest in this? Should be fully backward compatible and could write more tests if there is doubt.

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

Successfully merging this pull request may close these issues.

1 participant