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

Add a streamElement property to the turbo:before-stream-render event #20

Closed
wants to merge 2 commits into from
Closed

Conversation

nbgoodall
Copy link

@nbgoodall nbgoodall commented Dec 23, 2020

This adds a streamElement property to the detail of the turbo:before-stream-render. Feel free to do with it as you wish!

Personally I'm using this for intercepting the event to smoothly transition between the frames, e.g.:

document.addEventListener('turbo:before-stream-render', function(event) {
  event.preventDefault()

  /* Transition the old frame away ... */

  event.detail.streamElement.performAction()
})

Thank you for all your work! 🙏

This adds a `newTemplate`  property to the detail of the `turbo:before-stream-render` event containing the new template content, similar to `newBody` in the `turbo:before-render` event.
@panda-madness
Copy link

panda-madness commented Dec 23, 2020

Wouldn't it be better to just pass in a reference to the entire StreamElement? That way we get access to every aspect of the stream action, not just the template. Could also straight up call performAction directly instead of manually recreating that bit.

@nbgoodall nbgoodall changed the title Add a newTemplate property to the turbo:before-stream-render event Add a streamElement property to the turbo:before-stream-render event Dec 23, 2020
@sstephenson
Copy link
Contributor

Thanks for the patch! You can already access the stream element using the event.target property, so I don't think we need to pass anything along in the details object 👍

@pySilver
Copy link

pySilver commented Nov 14, 2022

Current example is:

document.addEventListener("turbo:before-stream-render", function (event) {
  event.preventDefault();

  /* Transition the old frame away ... */
  console.log("turbo:before-stream-render", event.detail.newStream.target);

  event.detail.newStream.performAction();
});

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

Successfully merging this pull request may close these issues.

4 participants