Akita: StateHistoryPlugin with multiple stores undo/redo

Created on 15 Apr 2019  Â·  8Comments  Â·  Source: datorama/akita

First of all thank's so much @Datorama and @NetanelBasal for the akita project! It's awesome and I love it!

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ x] Support request
[ ] Other... Please describe:

Current behavior

I have 3 Entities similar to the movies, genre and actor demo. I wanted to add StateHistoryPlugin to add undo and redo features. I do it with:
this.stateHistory = new StateHistoryPlugin(this.moviesQuery);

Then I do 3 actions:

1 - change movie title name

2 - change genre name

3 - delete actor

When I press undo ( this.stateHistory.undo();) I get the action 1 undone.

Expected behavior

The expected behaviour is "the expected" but what if we get the action 3 undone?

What is the motivation / use case for changing the behavior?

We have 3 different stores and what's happening is expected but:

  • is there a way to handle this situation and get action 3 undone instead of 1?
    if not:

    • do we need to keep which store was changed when and then apply the undo?

    • or best way is to combine the 3 stores into one?

Thanks again for the awesome work!

Most helpful comment

@shaharkazaz will work on that.

All 8 comments

Hey,

Based on your example use-case, you can do the following:

[stateHistoryMovies, stateHistoryGenres, stateHistoryActors].forEach(plugin => plugin.undo())

It will undo the latest state in all the stores. It's a workaround but I think it could be a great addition to Akita.

thank's for the suggestion :)

It will undo the latest state in all the stores

I might don't understand your use-case. Can you please create a demo in stackblitz so we can experiment with the use-case?

Sorry didn't had much time to get an example working. Will try to get the demo done this weekend.

So here is my example:

https://stackblitz.com/edit/akita-movies-undo-redo-3querys-history

In this example I added a button that perform 3 actions one on each entity - movie, genre and actor. When the user presses undo he is expecting to undo all the 3 actions. But only the movie action is undone because its the only being passed to the state history plugin.

The option that you provided above would solve this problem:
[stateHistoryMovies, stateHistoryGenres, stateHistoryActors].forEach(plugin => plugin.undo())

But it would not differentiate when the user performed each action alone so when the user presses undo it will perform one undo in each store even if the user wanted to undo action by action.

I think we need some CombinedStateHistoryPlugin. What do you think?

Thanks.

@shaharkazaz will work on that.

A quick update. We decided that we're not going to do that because there was no demand. We'll reconsider if there will be a demand — closing for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johanrin picture johanrin  Â·  7Comments

DmitryEfimenko picture DmitryEfimenko  Â·  6Comments

stherrienaspnet picture stherrienaspnet  Â·  3Comments

NetanelBasal picture NetanelBasal  Â·  6Comments

eitanfr picture eitanfr  Â·  4Comments