ngrx-state-switcher
State switcher meta reducer for @ngrx/store (Undo
-Redo
functionality).
Dependencies
ngrx-state-switcher
depends on @ngrx/store and Angular 2.
Usage
npm install ngrx-state-switcher --save
- Import
compose
andcombineReducers
from@ngrx/store
and@ngrx/core/compose
- Import
StateSwitcher
class fromngrx-state-switcher
; - Create instance of
StateSwitcher
class - Invoke
getStateReducer
method ofStateSwitcher
and get result (as function, let it bestateSwitchReducer
). - Add
combineReducers
after stateSwitchReducer and invoke composed function with application reducers as an argument toprovideStore
.
;;;;;; document.addEventListener'DOMContentLoaded', main;
API
StateSwitcher(actionsUnderPolicy: StateSwitchPolicy[]);
Arguments
actionsUnderPolicy
(array ofStateSwitchPolicy
): names of actions that will be excluded fromStateSwitcher
flow.
export enum Policy {
ALWAYS,
FIRST_ONLY,
EXCEPT_FIRST
}
export interface StateSwitchPolicy {
actionName: string;
policy: Policy;
}
Apart from that you can use preventDefaultInit
method of StateSwitcher
class to exclude default ngrx
actions from StateSwitcher
flow.
Example
;; ;;;;; ;; ; ;;
You can see here working example.