- From: Joseph Orbegoso Pea <notifications@github.com>
- Date: Sat, 17 Sep 2016 16:45:08 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/546/247814921@github.com>
Or did I misunderstand what you meant?
On Sep 17, 2016 4:44 PM, "/#!/JoePea" <joe@trusktr.io> wrote:
> > Since attributes are notified as soon as the element is upgraded,
>
> Not true, if attributes exist on the element before they are upgraded,
> Chrome doesn't call your attributChangedCallback (I guess technically, the
> attribute didn't change after the instance was made).
>
> On Sep 16, 2016 4:09 AM, "Andrea Giammarchi" <notifications@github.com>
> wrote:
>
>> @chris-morgan <https://github.com/chris-morgan> you could have a simple
>> convention like:
>>
>> class MyImage extends HTMLElement {
>>
>> static get observedAttributes() {
>> return ['onerror', 'onload'];
>> }
>>
>> attributeChangedCallback(name, oldValue, newValue) {
>> if (/^on/.test(name)) {
>> if (newValue) {
>> this[name] = newValue;
>> this.addEventListener(name.slice(2), this);
>> } else {
>> delete this[name];
>> this.removeEventListener(name.slice(2), this);
>> }
>> } else {
>> // every other attribute logic
>> }
>> }
>>
>> // any event previously registered through the instance
>> // will pass through this listener
>> handleEvent(e) {
>> return this['on' + e.type](e);
>> }
>>
>> }
>>
>> Since attributes are notified as soon as the element is upgraded, you'll
>> have your events and, whenever such attribute will be removed, or changed,
>> you'll have them reflected.
>>
>> The good part of using the instance as listener is that you'll never end
>> up with double listeners or never removed one (like unhanded bound events
>> would be) so it's quite easy to circumvent the current limit when it comes
>> to custom attributes, keeping the on prefix like the de-fact standard to
>> define an event.
>>
>> —
>> You are receiving this because you commented.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/w3c/webcomponents/issues/546#issuecomment-247059876>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AASKzlnIMXZbTc8RGvWWXWb26eBj5T6Oks5qqBgmgaJpZM4Jjlhf>
>> .
>>
>
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/546#issuecomment-247814921
Received on Saturday, 17 September 2016 23:45:49 UTC