28
loading...
This website collects cookies to deliver better user experience
FeatureStore
API:setState()
update the feature stateselect()
select state from the feature state object as RxJS Observableeffect()
run side effects like API calls and update feature stateundo()
easily undo setState actions (requires the UndoExtension)get state()
imperatively get the current feature stateStore
APIFeatureStore
APIFeatureStore
API and fall back to the Redux Store
API to implement the really complex features in your application.setState()
the Feature Store dispatches its setState action (with the new state as action payload) and the feature reducer will update the feature state accordingly.FeatureStore
source here.ComponentStore
expose state as RxJS Observables (using the select
method). With the methods setState
and patchState
the state can be updated.Store
, Query
, EntityStore
and more. Store
is build on top of RxJS/BehaviorSubject (see here). select
on a Query
instance). The update
method of Store
is used to update the state.Store
API (which is very similar to @ngrx/store and @ngrx/effects). FeatureStore
API. FeatureStore
. select
method) inform about state changes and the state can be changed by calling setState
.number
or string
.interface CounterState {
count: number;
}
const initialState: CounterState = {
count: 42
}
FeatureStore
:@Injectable({providedIn: 'root'})
export class CounterStateService extends FeatureStore<CounterState> {
count$: Observable<number> = this.select(state => state.count);
constructor() {
super('counter', initialState)
}
increment() {
this.setState(state => ({count: state.count + 1}))
}
decrement() {
this.setState(state => ({count: state.count - 1}))
}
}
ComponentStore
and provide an initial state:@Injectable({providedIn: 'root'})
export class CounterStateService extends ComponentStore<CounterState> {
count$: Observable<number> = this.select(state => state.count);
constructor() {
super(initialState)
}
increment() {
this.setState(state => ({count: state.count + 1}))
}
decrement() {
this.setState(state => ({count: state.count - 1}))
}
}
ComponentStore
instance lives independently.Store
and the other one extends Query
:@Injectable({providedIn: 'root'})
@StoreConfig({ name: 'counter' })
export class CounterStateService extends Store<CounterState> {
constructor() {
super(initialState)
}
increment() {
this.update(state => ({count: state.count + 1}))
}
decrement() {
this.update(state => ({count: state.count - 1}))
}
}
@Injectable({providedIn: 'root'})
export class CounterQuery extends Query<CounterState> {
count$: Observable<number> = this.select(state => state.count);
constructor(store: CounterStateService) {
super(store);
}
}
Store
is similar to the other setups. A feature key is provided via the @StoreConfig
decorator.Query
and provide the Store
instance.Query
and the Store
instance in order to read and write state.Store
(!) instance using store.select
.combineLatest
or withLatestFrom
to combine state from other Feature Stores with state Observables of your current Feature Store.select
method also accepts a bunch of Observables to depend on (see docs here). ComponentStore
instances.combineQueries
to combine state from different Query
instances. combineQueries
is basically RxJS combineLatest
. createSelector
) is also great for Composition: Build selectors by combining existing selectors.createFeatureSelector
and createSelector
functions for the Redux Store
API and for the FeatureStore
API.switchMap
, mergeMap
, etc.).Store
instance.FeatureStore
and the Redux Store
API can undo specific state changes.undo
method. setState
, update
or by dispatching an Action in Redux). ImmutableStateExtension
is added to the MiniRx Store both the Redux Store
API and the FeatureStore
API will use immutable data.updater
method, tapResponse
operator