Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Add State to Store #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Bielik20
Copy link

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.

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

Successfully merging this pull request may close these issues.

1 participant