Outlets: Add observers for controller element attributes#624
Merged
marcoroth merged 6 commits intoJan 30, 2023
Conversation
Contributor
Author
|
@marcoroth since you authored the original Outlets implementation, I'd really appreciate some code review on this. |
e23e112 to
93290ea
Compare
IsraelDCastro
approved these changes
Dec 15, 2022
marcoroth
reviewed
Dec 22, 2022
Member
marcoroth
left a comment
There was a problem hiding this comment.
Thanks @seanpdoyle for catching this oversight!
The outcome of this PR looks good to me. I left some comments and I'm curious to hear what you think.
marcoroth
reviewed
Dec 22, 2022
In some cases, calls to `Element.setAttribute`, `Element.removeAttribute`, `Node.appendChild`, or `Element.remove` must be followed up with a call to `await this.nextFrame` so that Stimulus has an opportunity to synchronize. This commit introduces asynchronous helper method versions of those calls that bake-in the subsequent call to `this.nextFrame`.
With the current Outlet implementation, they're only ever connected or disconnected when an element _matching_ the outlet selector connects or disconnects. The selector _declared on the controller_ element can only ever be set once: when it's connected. If that attribute ever changes (for example, when it's set to a new value or removed entirely), the outlets are not updated. This commit adds test coverage to ensure the list of outlets and their items is synchronized with changes on both sides: when matching elements are connected and disconnected _as well as_ when the selector that dictates whether or not they match is added, updated, or removed. To do so, this commit extends the `SelectorObserver` to also manage the lifecycle of an `AttributeObserver` instance alongside its internally managed `ElementObserver`.
0178b27 to
971004a
Compare
e77a1d3 to
971004a
Compare
marcoroth
approved these changes
Jan 30, 2023
Member
marcoroth
left a comment
There was a problem hiding this comment.
This looks good me now! Thanks @seanpdoyle!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Extract
DomTestCasehelpersIn some cases, calls to
Element.setAttribute,Element.removeAttribute,Node.appendChild, orElement.removemustbe followed up with a call to
await this.nextFrameso that Stimulushas an opportunity to synchronize.
This commit introduces asynchronous helper method versions of those
calls that bake-in the subsequent call to
this.nextFrame.Outlets: Add observers for controller element attributes
With the current Outlet implementation, they're only ever connected or
disconnected when an element matching the outlet selector connects or
disconnects. The selector declared on the controller element can only
ever be set once: when it's connected. If that attribute ever changes
(for example, when it's set to a new value or removed entirely), the
outlets are not updated.
This commit adds test coverage to ensure the list of outlets and their
items is synchronized with changes on both sides: when matching elements
are connected and disconnected as well as when the selector that
dictates whether or not they match is added, updated, or removed.
To do so, this commit extends the
OutletObserverto also manage thelifecycle of an
AttributeObserverinstance alongside its internallymanaged
SelectorObserver.