ngrx-actions
ngrx-actions copied to clipboard
Add State to Store
Hello, while writing reducers each action within one store takes the state of the same type as an input. It could be easily omitted by moving the state to the base class.
It would transform this:
@Store<MyState>({ ... })
export class MyStore {
@Action(Action1)
action1(state: MyState, action: Action1) {
return { ...state, action.payload };
}
// ...
}
into that:
@Store<MyState>({ ... })
export class MyStore extends BaseStore<MyState> {
@Action(Action1)
action1(action: Action1) {
return { ...this.state, action.payload };
}
// ...
}
The change that I made is very simple and doesn't conflict with the existing solution. The only downside is that it does not work for effects placed in the store because of their asynchronous nature.
What do you think about my approach? I feel like it would help to reduce what is left off so much hated boilerplate.