customElement as "templateController"
- Dominant language
- TypeScript
- Stars
- 113
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
Custom elements should be able to be "template controllers". What I mean is the following:
Currently, to create a custom element that uses it's light DOM (child nodes) as a view/view factory, you have to jump through quite a few hoops. First, you need to add `@processContent(false)`, then, you need to inject `ViewResources, ViewSlot, ViewCompiler, Container, Element`, and lastly, in the constructor you need to do this whole circus:
``` js
const fragment = document.createDocumentFragment();
let child;
while ((child = element.firstElementChild) !== null) {
fragment.appendChild(child);
}
this.viewFactory = viewCompiler.compile(fragment, viewResources);
this.container = container;
this.viewSlot = viewSlot;
```
If this was a `templateController`, I'd be able to simply inject a `BoundViewFactory` and the `ViewSlot` and call it a day. My point is, I don't really care about the view resources, the container being used, or even the element in question. I just need all those things to go through a bunch of formalities to get the same sort of functionality that you can get for free on custom attributes, and I have to do it for every custom element I create that wants this kind of functionality.
Contributor guide
Research direction
Start by reading the existing custom-element and template-controller paths, especially the BoundViewFactory and ViewSlot usage described in the issue. Compare them with the manual ViewResources, ViewCompiler, Container, and Element setup. Done means a custom element can use its light DOM as a view or view factory without repeating that setup, with relevant behavior covered by the project’s existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100