element-behaviors icon indicating copy to clipboard operation
element-behaviors copied to clipboard

Should element behaviors be accessible on elements directly, or in a global map?

Open trusktr opened this issue 7 years ago • 1 comments

For example, should it be

const el = document.querySelector('div')

// suppose el is <div has="foo bar baz">

el.behaviors.add('click-logger')
el.behaviors.remove('foo')

// now el is <div has="bar baz click-logger">

which means .behaviors would exist on Element.prototype, or should it be something like

const el = document.querySelector('div')

// suppose el is <div has="foo bar baz">

elementBehaviors.of(el).add('click-logger')
elementBehaviors.of(el).remove('baz')

// now el is <div has="bar baz click-logger">

It seems like a global map would be easier to optimize, rather than increasing the size of the prototype of all elements by default. ?

trusktr avatar Feb 01 '18 20:02 trusktr

I think global is a good idea. This feature is also missing for custom elements .

drBenway avatar Mar 25 '22 07:03 drBenway