A class representing a substore in the NgRedux store.

Type Parameters

  • State

    The state shape of the substore.

Hierarchy

  • AbstractStore<State>
    • SubStoreService

Constructors

Properties

_store$: ReplaySubject<State> = ...

Angular subject store corresponds to store change event and trigger rxjs change event

basePath: PathSelector

The base path of the substore.

hashReducer: number

The hash value for this reducer.

localReducer: Reducer<State>

The reducer of the substore.

reducerService: ReducerService

An instance of the ReducerService used to register and replace reducers for the store.

rootStore: NgRedux<any>

The NgRedux store.

subscription: Subscription

An RxJS Subscription object representing the subscription to the store state changes.

Methods

  • 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.

    Example

      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);
    }

    Returns

    The sub-store service instance.

    Type Parameters

    • SubState

      The type of the sub-store state.

    Parameters

    • basePath: PathSelector

      The base path of the sub-store.

    • localReducer: Reducer<SubState>

      The local reducer of the sub-store.

    Returns SubStoreService<SubState>

  • Dispatches an action object with an additional metadata object containing the hash and path of the sub-reducer.

    Returns

    The dispatched action object.

    Type Parameters

    • Action extends AnyAction<Action>

      The type of action to dispatch.

    Parameters

    • action: Action

      The action object to dispatch.

    Returns Action

  • Returns the current state of the substore.

    Example

      incrementIfOdd(): void {
    const { counter } = this.ngRedux.getState();
    if (counter % 2 !== 0) {
    this.increment();
    }
    }

    Returns

    The current state of the substore.

    Returns State

  • Replaces the current local reducer with a new one.

    Example

    const newRootReducer = combineReducers({
    existingSlice: existingSliceReducer,
    newSlice: newSliceReducer
    })

    ngRedux.replaceReducer(newRootReducer)

    Returns

    Parameters

    • nextLocalReducer: Reducer<State>

      The new local reducer to replace the current one.

    Returns void

  • Select a slice of state to expose as an observable.

    Example


    constructor(private ngRedux: NgRedux<IAppState>) {}

    ngOnInit() {
    let { increment, decrement } = CounterActions;
    this.counter$ = this.ngRedux.select('counter');
    }

    Returns

    An Observable that emits items from the source Observable with distinct values

    Type Parameters

    • SelectedType

      The type of the selected slice of state

    Parameters

    • Optional selector: Selector<State, SelectedType>

      A key or function to select a part of the state

    • Optional comparator: Comparator

      A comparison function called to test if an item is distinct from the previous item in the source

    Returns Observable<SelectedType>

  • Subscribe to changes in the substore's state.

    Example

      constructor(
    private ngRedux: NgRedux<IAppState>,
    private actions: CounterActions,
    ) {
    this.subscription = ngRedux
    .select<number>('count')
    .subscribe(newCount => (this.count = newCount));
    }

    ngOnDestroy() {
    this.subscription.unsubscribe();
    }

    Returns

    • The unsubscribe function to remove the subscription.

    Parameters

    • listener: (() => void)

      The callback function to be executed on state changes.

        • (): void
        • Returns void

    Returns (() => void)

      • (): void
      • Returns void

Generated using TypeDoc