animotionjs / animotion

🪄 Create beautiful presentations with Svelte
https://animotion.pages.dev
MIT License
1.38k stars 41 forks source link

Perform Transition/Action callbacks when navigating backwards through a presentation #36

Closed williamviktorsson closed 2 months ago

williamviktorsson commented 2 months ago

I've found that I'd like to reapply the state change in a do callback when traversing backwards, and I'd like to not duplicate this code in following undo callbacks to achieve this.

I propose that when an item is focused (the last Action/Transaction), there's a callback that is performed no matter what way the presentation is navigated.

Blankeos commented 1 month ago

So do I just use this?

<Action focused={() => console.log("Focused")} /> 

It does not seem to get logged at all.

I'm on:

"svelte": "5.0.0-next.167",
"@animotion/core": "^1.0.15",
Blankeos commented 1 month ago

@williamviktorsson Was the whole point of the issue btw so that you don't need to do this?

<Action
    do={() => {
        console.log("Apply state change");
    }}
    undo={() => {
        console.log("Apply state change");
    }}
/> 

Why not just do this?

<script>
    function handleFocus() {
        console.log("Apply state change");
    }
</script>
<Action
    do={handleFocus}
    undo={handleFocus}
/> 

I also don't get why undo had to be removed.

I have custom animations that tie in the events of or . Specifically:

mattcroat commented 1 month ago

@Blankeos it makes more sense it's the default behavior for do so you don't have to repeat yourself so undo for that reason is redundant