Re: Custom Elements: 'data-' attributes

On 13/05/2014 10:37, Anne van Kesteren wrote:
> Sole had the idea of providing hooks for attributes so a component can 
> say it handles them rather than the user agent. That makes a lot of 
> sense to me. That way you can grab any name, even existing ones. 
Thank you for adding this idea to the list, Anne!
Now that you've involved me I have to emerge from the Lurkers in the 
Shadow tree and add in the rest of my comments:

As a developer which likes the idea of web components because they will 
allow me to write "semantic code" I am concerned about prefixing the 
attributes of *my* components with data-. It not only is unneeded noise 
but it also clashes with the understanding I had of how web components 
should work. If they are custom, they *are* custom--I should have total 
ownership over them.

Hypothetical comparison:

<audio-synth osc1="square" osc2="sine" frequency="320"></audio-synth>

where I can grab a reference and access this in JS with

synth.osc1 = ...
synth.frequency = ...

vs

<audio-synth data-osc1="square" data-osc2="sine" 
data-frequency="320"></audio-synth>

synth.dataset['osc1'] = ...
synth.dataset['frequency'] = ...

Plus this second method looks like it wouldn't allow me to use custom 
setters/getters. Specially setters! When you're building components you 
want to do fancy things when you modify attributes, for example update 
the position of a knob with a smooth transition, and not just update the 
attribute value.

I'm grateful to James Graham and Anne V.K. for explaining me the 
reasoning behind this prefixing idea: so that both current and FUTURE 
global attributes do not clash with the attributes I choose to use in my 
component.

And that's where I suggested leaving attribute handling to the 
component. If it "self-registers" as handling a certain attribute, then 
don't let the UA handle it as it would do if unregistered.

Hope that makes sense! :-)

sole

-- 
//
// http://soledadpenades.com   //  @supersole //
// GIF HACKTIVIST // Mozilla Apps Engineering //
                                               //

Received on Wednesday, 14 May 2014 13:25:18 UTC