Adds a new "pending object" to construct the Turbo Stream response with some shorthands which should cover most cases (see example syntax)
Changed
Changes the way we generate Turbo Stream HTTP responses to closely match the turbo-rails API, but with some Laravel sugar on it;
BC: the response()->turboStream() macro changed the return type. It now returns an instance of the Tonysm\TurboLaravel\Http\PendingTurboStreamResponse class.
Removed
BC: Removes the usage of custom turbo stream views when generating the turbo stream response passing a model. These should now use the response()->turboStreamView() helper instead.
BC: Removes the convention for overriding things like the resource name, DOM ID, partial view name and partial data from the models (which you could do by implementing the hotwireTargetResourcesName, hotwirePartialName, hotwirePartialData, and hotwireTargetDomId methods on the model). Prefer using available overrides instead. This is an attempt to reducing the conventions and making things more explicit.
There was not really a way to manually construct a Turbo Stream response before. It relied on conventions or using custom turbo stream views, which had precedence over generating a Turbo Stream response.
The precedence of custom Turbo Stream views is now gone. If you want to use custom turbo stream views, you can manually do that by using the response()->turboStreamView() helper (Breaking Change).
Now, you can manually construct Turbo Stream responses, like so:
The old style of passing the model as a param to the turboStream() macro still works. However, it won't pick up the custom turbo stream views anymore.
return response()->turboStream($comment);
This will render a remove Turbo Stream if the model was deleted (or if it's trashed, in case we have a soft-deleted model), or a append if it was a recently created model (you can override the action as the second parameter with this syntax), or a replace Turbo Stream if the model was just updated (you can also override the action as the second parameter with this syntax for updated too), something like:
response()->turboStream($comment, 'prepend'); // if the model was created, it will render a prepend Turbo Stream. Default: append
response()->turboStream($comment, 'update'); // if the model was updated, it will render an update Turbo Stream. Default: replace
Added
Changed
turbo-rails
API, but with some Laravel sugar on it;response()->turboStream()
macro changed the return type. It now returns an instance of theTonysm\TurboLaravel\Http\PendingTurboStreamResponse
class.Removed
response()->turboStreamView()
helper instead.hotwireTargetResourcesName
,hotwirePartialName
,hotwirePartialData
, andhotwireTargetDomId
methods on the model). Prefer using available overrides instead. This is an attempt to reducing the conventions and making things more explicit.There was not really a way to manually construct a Turbo Stream response before. It relied on conventions or using custom turbo stream views, which had precedence over generating a Turbo Stream response.
The precedence of custom Turbo Stream views is now gone. If you want to use custom turbo stream views, you can manually do that by using the
response()->turboStreamView()
helper (Breaking Change).Now, you can manually construct Turbo Stream responses, like so:
There are also a couple of shorthand syntaxes, like so:
These will figure out the correct target, action, and view/partial to use based on the conventions.
They also return the same "pending object" as the manually constructing responses one so you can override the defaults, like so:
The old style of passing the model as a param to the
turboStream()
macro still works. However, it won't pick up the custom turbo stream views anymore.This will render a
remove
Turbo Stream if the model was deleted (or if it's trashed, in case we have a soft-deleted model), or aappend
if it was a recently created model (you can override the action as the second parameter with this syntax), or areplace
Turbo Stream if the model was just updated (you can also override the action as the second parameter with this syntax for updated too), something like:Issue: https://github.com/tonysm/turbo-laravel/issues/18
TODO: