-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attrs initialization without @attr
decorator
#207
Comments
In the guide we mention calling |
Hey @keithamus! Yes, you're right. I'm not calling
I created those 2 issues hoping we could tackle them one by one, but now it seems to me they're more interdependent than I thought. Sorry about that 😅 Maybe this summary will make it easier:
// Using a word "instance" everywhere for simplicity
/**
* Maps instances to their attributes
*/
const attrs = new WeakMap(...)
/**
* Adds a new attribute to the mapping
*/
function attr(proto, key) {
// The ONLY place where `attrs` is populated
}
/**
* Defines computed properties on an instance with values from DOM
*/
function initializeAttrs(instance, names = []) {
// Takes attribute names from the `names` argument OR from the `attrs` variable
}
/**
* Defines a static computed `observedAttributes` property on an instance
*/
function defineObservedAttributes(classObject) {
// Takes attribute names ONLY from the `attrs` variable
} Please let me know if it's clear or not. I can also prepare an example repo or something 🙂 |
Thanks for the detailed reply @kristoforsalmin! We can work to fix the breakage, such that existing code continues to work (after all that’s the semver contract!). We’re working on a 2.0 release which significantly changes how these fields are managed, especially for non-decorator code. It might be preferable to wait for this release - we hope to get a pre-release out this week. In 2.0, instead of using the decorator you can do the following: import {controller, attr} from '@github/catalyst'
class AnExampleElement extends HTMLElement {
static [attr.static] = ['open']
}
AnExampleElement = controller(AnExampleElement) |
@keithamus cool! I'll just stick to whatever works now and wait for the upcoming release then 👍 Feel free to close those 2 issues (or keep them, if it makes sense). My main goal was to simply let you know about the behavior and my findings. Majority of people are probably using TypeScript anyway, so they won't even notice 😄 And thanks for making Catalyst! So far I only enjoyed its simple design and determination to fix "boilerplaty" aspects of Web Components with just a pinch of features on top and no more than that. |
Hi there 😄
After upgrading from v1.1.4 to v1.3.2, I noticed that my attributes were no longer shadowed by
initializeAttrs()
. I started digging and stumbled upon this piece of logic introduced in #191:catalyst/src/attr.ts
Line 39 in a8fb3ba
It prevents
initializeAttrs()
from doing anything the second time around, thus skipping the manual initialization of attributes. Also, it seems like this change was one of the main things addressed by the above-mentioned PR.So, what would be the correct way now to initialize the attributes without the
@attr
decorator?Thanks!
Example
controller(InfoMessage)
wraps originalconnectedCallback()
and calls:catalyst/src/core.ts
Line 14 in a8fb3ba
InfoMessage
is marked asinitialized
(attrs.ts
):catalyst/src/attr.ts
Line 40 in a8fb3ba
connectedCallback()
is executed, butinitializeAttrs()
would hit that early-return condition.this.open
is stuck in its default state (true
) 😔The text was updated successfully, but these errors were encountered: