angular-store
  • @angular/store
  • State
  • Reducer
  • Action
  • Dipatch
  • Selector
  • MISCELLANEOUS
    • Methods
Powered by GitBook
On this page
  • Get State
  • Update State

Action

Action receives payload from dispatch when it matches type of dispatcher.

let's see how to Implement it.

this.store.dispatch({ type: 'username', payload: '@angular/store'});

@Action(UPDATE_USERNAME)
public updateUsername(payload: string, { getState, updateState }: IState) {
  const state = getState<AppState>();
  updateState({ key: username.key, payload });
}

// multi action
@Action([UPDATE_USERNAME, ADD_USER ])
public onMultiUpdate(payload: string, state: IState) {
  console.log('both changes!!', payload);
}

each @Action method will have two arguments one payload and other is state.

Payload is same value which being passed when there's a dispatch.

state is an Object with two methods, one is getState and updateState

Get State

this method returns current state of application.

const currentState = state.getState();

Update State

this method helps us to update state key with some value.

state.updateState({ key: username.key, payload: newData });

PreviousReducerNextDipatch

Last updated 6 years ago