-
Notifications
You must be signed in to change notification settings - Fork 50
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
@attr has discrepencies with attributeChangedCallback
#117
Comments
I'm mostly leaning towards 2. It feels like the least amount of divergence from Web Components follows our thinking of making Web Components easier to work with. |
How do you feel about it abusing/violating the contract that Also an added caveat |
I'd perfer the 1st mentioned solution: Document this gotcha and just let developers deal with it.
In many cases the |
Thanks @blackgwe that's some great feedback! |
The
attributeChangedCallback
function is called whenever an observed attribute is set, added or removed. TheattributeChangedCallback
is called with the raw values of the attribute name, old value and new value.This can be surprising when using the
@attr
decorator which gives conveniences over the attributes by allowing for camel-cased names eliding theirdata-
prefix, and allowing types other thanstring
. It can also be surprising to seeattributeChangedCallback
being called withnull
when you type an@attr
asstring
.For example:
When this element first connects,
attributeChangedCallback('data-foo', null, '')
will fire.attributeChangedCallback
will never fire with'foo'
as the name, because that is a Catalyst concept and not a WC concept. The same is true of theboolean
type;attributeChangedCallback
will never fire with booleans for values. This means developers have to suddenly work around all of the conveniences@attr
offers them:Possible Solutions
attributeChangedCallback
with the mappedname
,oldValue
,newValue
attributeChangedCallback
has a fixed signature where it is only called withstring|null
and we're abusing that contract.attributeChangedCallback
to fire far more often, effectively double for each change to anattr
mapped value. Use cases which do not care about the argument values will see more - effectively redundant - calls.attrChangedCallback
) with the mappedname
,oldValue
,newValue
.const [realName, realOldValue, realNewValue] = this.attributeToAttr(name, oldValue, newValue)
)HelloWorldElement
's@attr name = ''
value could emithello-world-name-changed
.The text was updated successfully, but these errors were encountered: