0.2.0 • Published 7 years ago

fxstore v0.2.0

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

Creating commands and store state example

import { Command, ReducerCommand, State } from './command';

@State()
class Store1State {
  public IsLoading: boolean;
  public IsBusy: boolean;
  public Value: string;

  public initialize() {
    this.IsLoading = false;
    this.IsBusy = false;
    this.Value = '';
    return this;
  }
}

@Command(Store1State)
class IsLoadingCommand extends ReducerCommand<Store1State, any> {
  public Handle() {
    this.State.IsLoading = true;
  }
}

@Command(Store1State)
class IsBusyCommand extends ReducerCommand<Store1State, any> {
  public Handle() {
    this.State.IsBusy = true;
  }
}

@Command(Store1State)
class SetValueCommand extends ReducerCommand<Store1State, string> {
  public Handle() {
    this.State.Value = this.Payload;
  }
}

Dispatch a command example

const isLoadingCommand = new IsLoadingCommand();
isLoadingCommand.Dispatch();

const setValueCommand = new SetValueCommand();
setValueCommand.Dispatch('My new value');
  

Create a selector example

const o = createSelector<Store1State>(x => x.IsLoading, Store1State.name);