Closed vallsv closed 5 months ago
Hey @vallsv, I like this solution! I'm wondering if this achieves the same effect as the ignoreAction
param on setState
, however. Take a look at this crude example I whipped up in CodeSandbox.
The whole state is tracked via useUndoable here. Every time onMouseMove
is called, it'll call setPosition
with the final param, ignoreAction
, set to true
—this way, it'll only update the present
state. However, 300 milliseconds after you stop moving the mouse, setPosition
is called normally, and the state is updated as you'd expect.
It's a crude and not-very-performant example, but it demonstrates how events with a huge quantity of calls can be handled without polluting the state.
Does this generally fit your requirement or is there something else I'm not considering that your useUndoableWithIntermediate
hook covers?
Thanks for opening an issue, by the way! 😄
Thanks for your feedback. Sounds like the same use case.
I unfortunately don't have much time to play with it now , But ill go back to this task in couple of months.
Feel free to close this issue if you prefer, i could reopen it in case.
No worries! Feel free to reopen it when you get back to it :)
Hi,
I am working on complex interaction with multiple components supporting drag and drop.
I found out that it was much easier to handle that by wrapping your hook inside and own code, allowing me to handle a "live" state which is not yet part of the history.
For example during a mouse drag, all my components are aware of the new state, but this state is not yet part of the history. At the end of the mouse interaction it be came part of the history.
I call it "intermediate" state.
Would you be interested in such behavior, or by chance is there a way to setup your hook to behave this way?
Here is my actual code:
And I use it this way:
It works pretty well.