Skip to content
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

Should transition instances be reusable? #173

Closed
jakearchibald opened this issue Aug 3, 2022 · 2 comments
Closed

Should transition instances be reusable? #173

jakearchibald opened this issue Aug 3, 2022 · 2 comments

Comments

@jakearchibald
Copy link
Collaborator

jakearchibald commented Aug 3, 2022

const transition = new SameDocumentTransition();
transition.prepare(callback);
await transition.finished;

// Should this work:
transition.prepare(differentCallback);

My gut feeling is that one SameDocumentTransition instance should be used for one same document transition.

However, Animation objects can be restarted once they're complete, and can even have their target & keyframes modified. For example, their finished promise changes when the animation is cancelled, or changes from a 'finished' state to a 'not-finished' state.

However I'm not sure this model makes sense here. SameDocumentTransitions are meant to be a transition between states, whereas animations can be ongoing within a single state.

Maybe this points to a bigger design issue with the API: Is there any point in creating a SameDocumentTransition without preparing it?

We could avoid this issue altogether with a design like this:

const transition = document.stateTransition({
  async updateState() {
    // Perform the DOM update
    // (like our prepare callback)
  },
});

await transition.ready;
// Pseudos and animations are created
await transition.finished;
// Transition is complete

// transition.abandon() also exists
@khushalsagar
Copy link
Collaborator

We decided to not allow them to be reusable and its enforced in the spec text.

@jakearchibald did you still want to use this issue to track switching from a ctor to document.startTransition(..) so getting an object is coupled with starting a transition? Our last discussion was about both making sense, Animation allows you to construct and pass the object to lazily start the animation. I'm ok with the current ctor option and adding something like this later if needed.

@jakearchibald
Copy link
Collaborator Author

I'll roll it into #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants