iqqmuT
iqqmuT

Reputation: 843

Undo/Redo with server support in ngrx 4

Goal:

Implementing undo/redo functionality with server side support in Angular 4 project. For example, deleting an item from the server must be undoable with a corresponding (create) action.

There is a component for this: https://github.com/PowToon/redux-undo-redo

I'm trying to port that component using ngrx-store 4.

Problem:

I'm trying to convert the middleware into meta-reducer but it doesn't seem to be an easy task. How can I call dispatch in ngrx meta-reducer? If I can't, how could I implement a corresponding functionality?

Middleware: https://github.com/PowToon/redux-undo-redo/blob/master/src/createUndoMiddleware.js

Or if there is any easier way to reach my goal, what would it be?

Upvotes: 2

Views: 1499

Answers (2)

Jannic Beck
Jannic Beck

Reputation: 2425

You might want to have a look at ngrx-undoable

And especially the async-example

Disclaimer I'm the author of the library

Upvotes: 0

Todd Hansberger
Todd Hansberger

Reputation: 487

We are trying to accomplish something very similar, and we are using ngrx-effects. We use an effect to call the API to accomplish the original action, and add a second effect to store the inverse of the original action in the state. This way we have access to the original action's payload, and can access any part of the state if needed.

Upvotes: 3

Related Questions