-
Notifications
You must be signed in to change notification settings - Fork 38
fix(undo-redo): clearStack should also clear the previous item #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(undo-redo): clearStack should also clear the previous item #186
Conversation
Sorry for the huge Diff. |
@@ -22,39 +32,55 @@ describe('withUndoRedo', () => { | |||
'canRedo', | |||
'undo', | |||
'redo', | |||
'clearStack' | |||
'clearStack', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withUndoRedo
is used as plugin inside a store.
When the undo & redo stack shall be cleared clearStack
is called.
Currently, it is not clear which stack is cleared.
In fact, we are clearing two stacks.
Do we want to deprecate clearStack
in favor of resetUndoRedo
or clearUndoRedo
?
I guess reset*
fits better, @rainerhahnekamp .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @GregOnNet, regarding the reset functions: there’s an open discussion about taking a different approach. The idea is to avoid adding more methods directly to the signalStore, in order to prevent “polluting” the API with keywords that might be needed for other use cases in the future:
#160 (review)
So yes, I’m in favour of deprecating clearStack — but instead of introducing new store methods, we should provide standalone functions that can be used within patchState.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I understand correctly clearing the undo-redo-stack could become something like this.
patchState(store, state => reset({ undoStack: [], redoStack: []}));
// or if the internal state gets adjusted
patchState(store, state => reset({ undoRedo: ??? }));
// or with some type-literal wizardry
patchState(store, state => reset('undoRedo'));
Am I correct?
I also experience challenges managing the visibility of certain mechanics in the store.
It feels like there is "internal state" and "public state".
In consequence there are methods internal to the store and public ones.
Nevertheless, I do not think that the example clearStack
is "polluting" the API.
To me, it is the public API of the signalStoreFeature
.
So I absolutely expect this method to be in my store to handle my use-cases.
Adding reset
, causes an indirection, a developer might need to read about.
To me, it is not intuitive.
If I understood correctly, instead of "learning" about "clearStack" the API-user now needs to have knowledge about the shape of the state of the undo-redo-plugin.
Maybe it is worth to push the discussion about visibility to @ngrx/signal-store instead to reason about an overall solution for this topic.
UPDATE
What comes to my mind simplifying reset
a bit.
We could provide an abstraction to hide the details of which parts of the state are reset.
I guess, undoStack
& redoStack
still need to get part of the state, then:
import { resetUndoRedo } from '@angular-architects/ngrx-toolkit'
patchState(store, state => resetUndoRedo(state))
// or shorthand
patchState(store, resetUndoRedo)
// or making resetUndoRedo call patchState
resetUndoRedo(store) // But now, another indirection. The relation to patchState and how it is operating with the store is hidden.
Do you think you can manage to do it without the reformatting? I think it is better for the Git history (but also review), if we only see the real changes. We can always do a big formatting PR afterwards, but that would then be separated from that one. |
Hi Rainer, yes I can. Currently, I guess, everyone has more effort to contribute if an unformatted file is touched. |
e84f534
to
c372275
Compare
I pushed the changes withoud reformatting @rainerhahnekamp . |
@GregOnNet, thanks, and a quick update from my side. I am currently on vacation and will return on Wednesday. You will hear from me then. |
Thanks for the update, Rainer. |
solves #185