The state shape of the substore.
Constructs a new SubStoreService instance.
The NgRedux store.
The base path of the substore.
The reducer of the substore.
Protected Readonly _store$Angular subject store corresponds to store change event and trigger rxjs change event
Private baseThe base path of the substore.
Private Readonly hashThe hash value for this reducer.
Private localThe reducer of the substore.
Private Readonly reducerAn instance of the ReducerService used to register and replace reducers for the store.
Private rootThe NgRedux store.
Private subscriptionAn RxJS Subscription object representing the subscription to the store state changes.
Configures a sub-store with a specified base path and local reducer. Carves off a 'subStore' or 'fractal' store from this one.
The returned object is itself an observable store, however, any selections, dispatches, or invocations of localReducer will be specific to that sub-store and will not know about the parent ObservableStore from which it was created.
This is handy for encapsulating component or module state while still benefiting from time-travel, etc.
onInit() {
// The reducer passed here will affect state under `users.${userID}`
// in the top-level store.
this.subStore = this.ngRedux.configureSubStore(
['users', userId],
userComponentReducer,
);
// Substore selections are scoped to the base path used to configure
// the substore.
this.name$ = this.subStore.select('name');
this.occupation$ = this.subStore.select('occupation');
this.loc$ = this.subStore.select(s => s.loc || 0);
}
The sub-store service instance.
The type of the sub-store state.
The base path of the sub-store.
The local reducer of the sub-store.
Dispatches an action object with an additional metadata object containing the hash and path of the sub-reducer.
The dispatched action object.
The type of action to dispatch.
The action object to dispatch.
Replaces the current local reducer with a new one.
const newRootReducer = combineReducers({
existingSlice: existingSliceReducer,
newSlice: newSliceReducer
})
ngRedux.replaceReducer(newRootReducer)
The new local reducer to replace the current one.
Select a slice of state to expose as an observable.
constructor(private ngRedux: NgRedux<IAppState>) {}
ngOnInit() {
let { increment, decrement } = CounterActions;
this.counter$ = this.ngRedux.select('counter');
}
An Observable that emits items from the source Observable with distinct values
The type of the selected slice of state
Optional selector: Selector<State, SelectedType>A key or function to select a part of the state
Optional comparator: ComparatorA comparison function called to test if an item is distinct from the previous item in the source
Sets the base path for the store, and subscribes to updates.
ngOnChanges() {
if(this.subStore)
this.subStore.setBasePath([ 'users', this.userId ]);
}
void.
The path selector.
Subscribe to changes in the substore's state.
constructor(
private ngRedux: NgRedux<IAppState>,
private actions: CounterActions,
) {
this.subscription = ngRedux
.select<number>('count')
.subscribe(newCount => (this.count = newCount));
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
The callback function to be executed on state changes.
Generated using TypeDoc
A class representing a substore in the NgRedux store.