-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alter Action Cable Element to be morph-compatible (#650)
Closes [#638][] Recent changes to integrate with morphing have altered the mental model for some Turbo custom elements, including the `<turbo-cable-stream-source>` element. Custom Elements' `connectedCallback()` and `disconnectedCallback()` (along with Stimulus' `connect()` and `disconnect()`) improved upon invoking code immediately, or listening for `DOMContentLoaded` events. There are similar improvements to be made to integrate with morphing. First, [observe attribute changes][] by declaring their own `static observedAttributes` properties along with `attributeChangedCallback(name, oldValue, newValue)` callbacks. Those callbacks execute the same initialization code as their current `connectedCallback()` and `disconnectedCallback()` methods. That'll help resolve this issue. In addition to those changes, it's important to emphasize this pattern for consumer applications moving forward. JavaScript code (whether Stimulus controller or otherwise) should be implemented in a way that' resilient to both asynchronous connection and disconnection *as well as* asynchronous modification of attributes. [#638]: #638 [observe attribute changes]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Components/Using_custom_elements#responding_to_attribute_changes
- Loading branch information
1 parent
9f5c846
commit 034c632
Showing
11 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<h1>Message #<%= @message.id %></h1> | ||
|
||
<%= turbo_stream_from @message %> | ||
|
||
<div id="<%= dom_id @message %>"> | ||
<%= render @message %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<%= turbo_stream.remove @message %> | ||
<%= turbo_stream.replace @message %> | ||
<%= turbo_stream.replace @message, "Something else" %> | ||
<%= turbo_stream.replace "message_5", "Something fifth" %> | ||
<%= turbo_stream.replace "message_5", "Something fifth", method: :morph %> | ||
<%= turbo_stream.update "message_5", "Something fifth", method: :morph %> | ||
<%= turbo_stream.replace "message_5", partial: "messages/message", locals: { message: Message.new(id: 5, content: "OLLA!") } %> | ||
<%= turbo_stream.replace @other_message, "Something fifth" %> | ||
<%= turbo_stream.replace @other_message, "Something fifth", method: :morph %> | ||
<%= turbo_stream.update @other_message, "Something fifth", method: :morph %> | ||
<%= turbo_stream.replace @other_message, partial: "messages/message", locals: { message: @other_message } %> | ||
<%= turbo_stream.append "messages", @message %> | ||
<%= turbo_stream.append "messages", partial: "messages/message", locals: { message: Message.new(id: 5, content: "OLLA!") } %> | ||
<%= turbo_stream.append "messages", partial: "messages/message", locals: { message: @other_message } %> | ||
<%= turbo_stream.prepend "messages", @message %> | ||
<%= turbo_stream.prepend "messages", partial: "messages/message", locals: { message: Message.new(id: 5, content: "OLLA!") } %> | ||
<%= turbo_stream.prepend "messages", partial: "messages/message", locals: { message: @other_message } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters