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

Docs: Add docs for reducer creators #1762

Closed
brandonroberts opened this issue Apr 17, 2019 · 9 comments · Fixed by #1924
Closed

Docs: Add docs for reducer creators #1762

brandonroberts opened this issue Apr 17, 2019 · 9 comments · Fixed by #1924

Comments

@brandonroberts
Copy link
Member

Follow-up to #1746

  • Document usage of createReducers
  • Keep references to using a reducer function with a switch case for current users
@alex-okrushko
Copy link
Member

I'll take it

@brandonroberts
Copy link
Member Author

👍

@realtomaszkula
Copy link

I think it would be beneficial to mention providing the reducers for AoT.

export function reducer(state, action) {
  return createReducer(...);
}

StoreModule.forFeature('feat', reducer)

@brandonroberts
Copy link
Member Author

Just for clarity, we're generating the reducer outside the exported function in the schematics, but the point still remains.

const someReducer = createReducer(...);

export function reducer(state: SomeState | undefined, action: Action) {
  return someReducer(state, action);
}

StoreModule.forFeature('feat', reducer)

@alex-okrushko
Copy link
Member

Putting it for myself so I don't forget all the info that's needed:

  • before/after of simple reducer
  • explain the need for proper typing of initialState
  • add the note to always pass state into on-reducers (so that the return type is inferred correctly)
  • explain how many actions could be provided for a single on-function
  • explain how to wire it up for forFeature - including the case if it's the only reducer for the feature
  • explain how to wire it up for forRoot (using token - if I won't have time to make it take the fn)

@fxck
Copy link

fxck commented Apr 29, 2019

Could on accept different kinds of the first param? Say if I wanted to catch any action that has entities on it? Should I handle this outside createReducer?

How about something like

on(({ entities }) => !!entities), (state, action) => state)

@timdeschryver
Copy link
Member

I don't think this is something we would add @fxck .

We're still reacting to unique actions.

@fxck
Copy link

fxck commented Apr 29, 2019

Yeah, well since you have to do this anyway #1762 (comment) I can live without that. :)

@alex-okrushko
Copy link
Member

@fxck I think that could result in more brittle logic. type should be the only thing that defines reducer behavior, I think.
At least that's how I see it ATM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants