angular-architects / ngrx-toolkit

Various Extensions for the NgRx Signal Store
MIT License
104 stars 17 forks source link

RFC: Simplified reducer method #5

Open rainerhahnekamp opened 6 months ago

rainerhahnekamp commented 6 months ago

The on method can accept the patched state as return type of the reducer function.

At the moment, it goes like this:

reducer(actions, on) {
  on(actions.flightsLoaded, (state, {flights}) => patchState(state, {flights})));
}

The new version could look like this:

reducer(actions, on) {
  on(actions.flightsLoaded, (, {flights}) => ({flights}))
}

Or if the state doesn't require the payload:

reducer(actions, on) {
  on(actions.resetSearch, {flights: []}) 
}
rosostolato commented 6 months ago

This would work with the proposal of https://github.com/angular-architects/ngrx-toolkit/issues/8.

It could allow you to use the same createReducer from @ngrx/store. Just like this approach: https://github.com/rosostolato/ngrx-signals-redux/blob/master/src/app/state/posts/posts.reducer.ts https://github.com/rosostolato/ngrx-signals-redux/blob/master/src/app/state/posts/posts.store.ts

rainerhahnekamp commented 6 months ago

So #8 is about adding a dependency to @ngrx/store. This is here is about the native version which only requires the Signal Store as dependency.