W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2013

[webcomponents]: Moving custom element callbacks to prototype/instance

From: Dimitri Glazkov <dglazkov@google.com>
Date: Wed, 6 Mar 2013 13:55:09 -0800
Message-ID: <CADh5Ky3bs6+5-+asd=i_40DRJGRQAcSZO5zsH-dRhQcKDMpZYw@mail.gmail.com>
To: public-webapps <public-webapps@w3.org>
Cc: Scott Miles <sjmiles@google.com>, Elliott Sprehn <esprehn@google.com>, Steve Orvell <sorvell@google.com>, Daniel Buchner <daniel@mozilla.com>, Adam Klein <adamk@google.com>, Hajime Morrita <morrita@google.com>, Blake Kaplan <mrbkap@mozilla.com>, William Chen <wchen@mozilla.com>
A few of browser/webdev folks got together and went (again!) over the
custom elements design. One problem stuck out: handling of "created"
callbacks (and other future callbacks, by induction) for derived
custom elements.

For example, if Raj defined a "create" callback for his <foo-raj>
element, and Lucy later extended <foo-raj> to make a <foo-lucy>
element. As spec'd today, Lucy has no obvious way of invoking Raj's
"create" callback, other than Raj and Lucy coming up with some
convention on how to collect and pass these callbacks.

Rather than watch developers come up with multiple, subtly different
such conventions, how can we, the browserfolk help? A couple of ideas:

1) Somehow magically chain "create" callbacks. In Lucy's case,
<foo-lucy> will call both Raj's and Lucy's callbacks.

* Magic is exciting
* Callbacks are tucked away safely in their own object, unexposed to
the consumer of custom elements.

* Magic of calling callbacks can't be controlled by the author. If
Lucy wants to override Raj's callback (or call it in the middle of her
callback), she can't.
* We're somewhat reinventing either prototype inheritance or event
listener model just for these callbacks.

2) Get rid of a separate lifecycle object and just put the callbacks
on the prototype object, similar to printCallback

* We make prototype inheritance do the work for us. Lucy can do
whatevs with Raj's callback.
* No magic, no special callback interface.

* The callbacks now hang out in the wind as prototype members. Foolish
people can invoke them, inspectors show them, etc.

I am leaning toward the second solution, but wanted to get your opinions.

Received on Wednesday, 6 March 2013 21:55:37 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:58 UTC