Adds Turbo Frame, Turbo Stream, and Turbo Stream From Blade components #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
x-turbo-frame,x-turbo-stream, andx-turbo-stream-fromso we can simplify usageThis pushes some decisions to the package itself. Below you can find the before/after of using each component.
Turbo Frame
We can now write it like:
Notice that you may pass an instance of an Eloquent Model to the
idproperty, which will be used to generate a DOM ID using thedom_idfunction that ships with the package. There's no need to use the@domidBlade directive here.The available properties are:
src,loading, andtarget. Additionally, any other attributes passed to the component will be rendered inside theturbo-frametag, so you may pass down aclassattribute, for instance.Turbo Stream
The Turbo Stream content needed to be wrapped in a
<templatetag (except for the "remove" action), so that decision was pushed to the Blade component itself, app-land code doesn't need to worry about this anymore.So, before we would write something like this:
And now you may write it like:
Notice that you may also pass an array which will then be used to generate the DOM ID using the
dom_idfunction that ships with the package, so there's no need to use the@domid()Blade directive here anymore. Also, the<template>tag wrapping the content of the Turbo Stream is gone, that's now the responsibility of the Blade component to add.Turbo Stream From
The package published a custom HTML Element for listening for Turbo Stream broadcasts. It can now be used with the
x-turbo-stream-fromBlade component.Before you would have:
Now, you may prefer doing it like so:
You may pass a string for the
sourceproperty or an instance of an Eloquent Model, from which the package will get the broadcasting channel name. You may also specify which channel type using thetypeproperty. By default, it will be "private", but you may also use "public" or "presence". Additionally, any other attribute passed down to this component will be forwarded to the underlying HTML Element.