Repository navigation
Conversation
The no-decorators example called defineObservedAttributes with a second argument that the function does not accept, so data-foo was never observed. Tag the field with attr() first, as verified in github#208. Closes github#208
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the guide now documents the supported attr() registration with the corrected defineObservedAttributes() usage.
No open issues 🎉
What changed in this PR
Updates the attrs guide so the decorator-free example correctly registers foo for observation using attr() before calling defineObservedAttributes().
Changes:
- Documents tagging the prototype property with
attr()for observation. - Adds
attrto the example import and invokes it onHelloWorldElement.prototype. - Removes the unsupported second argument from
defineObservedAttributes().
| File | Description |
|---|---|
| docs/_guide/attrs.md | Corrects the decorator-free attribute initialization and observation example. |
Review effort: Lite (adaptive)
This branch has not been deployed
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.
Closes #208
Hi Catalyst team! Thank you for maintaining Catalyst. The "What about without Decorators?" section in the attrs guide shows an example that cannot work as written: it calls
defineObservedAttributes(HelloWorldElement, ['foo']), butdefineObservedAttributesonly takes the class — the second argument is silently ignored, and since no field was tagged with@attr,data-foonever makes it intoobservedAttributes, soattributeChangedCallbacknever fires for it. A reader copying the example would end up with an element that looks equivalent to the@attrversion but never observes attribute changes.This PR fixes the example to tag the field with
attr()first (the workaround verified by the reporter in #208), then calldefineObservedAttributeswith just the class.attr,initializeAttrs, anddefineObservedAttributesare all already publicly exported, so no code changes are needed — docs only, no behavior change.Thank you for considering it, and please let me know if anything needs adjusting!