-
Notifications
You must be signed in to change notification settings - Fork 15
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
Slipscripts improvements: onUndo
and state
#97
Conversation
Hi, I'd love to test this, but in the presentation I'm working on, everything is kinda intertwined with a hacked-together animation system based on async iterators that attempts to implement #94 in userspace. Without proper integration between the two, I don't have much opportunity to easily get hands-on experience with the feature (I might find some time for this once I'm no longer on a deadline, though). One thing that came up while I was trying to find some place to nevertheless fit it in: what happens if The usecase here is as follows: I have a small part of the slide that I'm repeatedly re-randomizing to underline that it can be arbitrary. This looks as follows: startAnim = () => {
animInterval = setInterval(rerandomizeShit, 100);
}
startAnim();
return {
undo() {
clearInterval(animInterval);
// other stuff
x.undo(); y.undo();
}
}; However, having this in the background, off-screen, and possibly in another tab, can be quite CPU-intensive. Because of this, I'm pausing this animation once it goes off-screen: clearInterval(animInterval);
return {
undo() {
x.undo();
startAnim();
}
}; Now, with the let animInterval;
startAnim = () => {
animInterval = setInterval(rerandomizeShit, 100);
slip.onUndo(stopAnim);
};
stopAnim = () => {
clearInterval(animInterval);
slip.onUndo(startAnim);
};
startAnim(); With a follow-up script calling stopAnim(); The question to think about is — will this behave properly, or break things horribly? With this motivating example, I believe that it would be best if Actually, now that I think about it, you're mixing camelCase ( Regarding |
Hello, thanks a lot for taking the time to describe your use case!
I'll do the opam release and then think about this and #94 a bit more, but:
|
be7d778
to
e2d72e0
Compare
I kept the It should be possible to call I added a Thanks again for the suggestions! |
This PR adds two things in the
slip
object passed to scripts:slip.onUndo
value, that allows to register a callback to be run during undo (in reverse order).slip.state
object (initially empty) that is persisted between scripts.Documentation is updated.
@meithecatte I would be grateful if you can test those changes! The CI should built binaries, so you don't have to build locally.