Re: [w3c/webcomponents] Why do we really need hyphens? (#658)

Maybe what the web needs is an official component model that works **_on top_** of DOM (like Vue, React, etc), not **_in_** the DOM (Custom Elements are part of DOM, not on top of it).

Suppose we had something like a way to use selectors to associate components with DOM elements, officially, without creating anything that extends HTMLElement.

Maybe this is a good use-case for the `is=""`, not for extension, but for association of logic. There would be the element instance, and a separate instance of the class associated by is="" that doesn't extend from (should not) window.Node.

Or perhaps we just need an official declarative way of doing what jQuery has been doing for years. F.e.

F.e., let's take a div, and let's assign many behaviors to it:

```html
<div is="foo bar baz">
  ...
</div>
```

```js
components.define('foo', class Foo {...})
components.define('bar', class Bar {...})
components.define('baz', class Baz {...})
```

Which would simply play nicely along the current Custom Elements.

Of course, logic in components could clash, as with any sort of programming. So some care would need to be taken.

Defined components might have lifecycle hooks similar to Custom Elements.

Components' is not the element, it is just the instance of the component, and perhaps the constructor received the target element as an argument.

I'm just trying to throw some ideas out there so we can overcome limitations (f.e. naming with hyphens).

While we're thinking about it, we should also figure a way toocally name components, perhaps using shadow roots, so that

```js
root.components.define('foo', class Foo {...})
root.components.define('bar', class Bar {...})

root.components.define('baz', class Baz {...}, {
  // limit elements it can be used on
  allowedOn: ['div', 'p', '.some-class']
})
```

---

Just throwing ideas.

We just need something more modular and easier to scope, so different components can name their parts anything they want (just like with Vue or React components).

It would solve many problems in an official way.

-- 
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/658#issuecomment-325592918

Received on Tuesday, 29 August 2017 08:31:22 UTC