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

Improve types to support reducers with and without default handling #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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