Reputation: 885
I'm trying to implement undo/redo functionality in my application with @ngrx/store.
The basic concepts are described here (Redux): https://redux.js.org/recipes/implementing-undo-history
At some point in the recipe, the reducer function gets wrapped in what in Redux is called a reducer enhancer
A reducer enhancer (or a higher order reducer) is a function that takes a reducer, and returns a new reducer that is able to handle new actions, or to hold more state, delegating control to the inner reducer for the actions it doesn't understand.
What is the equivalent of this in NgRx? How can I construct the Store...
store.pipe(select('counter'));
... but wrap it inside an 'enhancer' function? Pseudocode:
undoable(store.pipe(select('counter'));
Someone pointed me to meta-reducers (https://ngrx.io/guide/store/metareducers), but the docs on that are not clearing things up for me.
Upvotes: 2
Views: 366
Reputation: 15505
Meta-reducers are the correct answer here. It has the same API as the redux docs, it receives a reducer and returns a reducer. Another example might be the use case to flush the state when the user signs out.
Upvotes: 2