wcc
wcc copied to clipboard
Feature/issue 87 jsx automatic observability
Related Issue
resolves #87
Summary of Changes
- Scan
renderandconstructorfunctions for usage ofthisto generateobservedAttributesandattributeChangedCallback
For example, this
export default class Greeting extends HTMLElement {
constructor() {
this.name = '';
}
render() {
const { name = 'World' } = this;
return (
<h1>Hello ${name}!</h1>
}
}
customElements.define('my-greeting', Greeting);
Would produce this
export default class Greeting extends HTMLElement {
static get observedAttributes() {
return ['name'];
}
constructor() {
this.name = '';
}
render() {
const { name = 'World' } = this;
this.innerHTML = `<h1>Hello ${name}!</h1>`;
}
}
customElements.define('my-greeting', Greeting);
Use it as
<my-greeting name="WCC"></my-greeting>
See a demo at https://github.com/thescientist13/todo-app/pull/3
TODOs
- [ ] Tests
- [ ] Match
thisusages at the top ofrenderfunction-
const showTodo = this.todo.completed ? true : false; -
const showTodo = this.todo.completed;
-
- [ ] Match
thisusages inreturnofrenderfunction (JSX)<span>{this.todo.description}</span> - [ ] Match
thisusages at top ofconstructorinifor ternary statements - [x] Try and get an example of
attributeChangedCallback - [ ] Documentation
- [ ] Other cases?
Questions
- [ ] Currently this assumes attributes map to properties. Need to distinguish the two?
- [ ] Do we need to match in both
renderandconstructor? - [ ] Check if
observedAttributesorattributeChangedCallbackexists, and merge? Or defer to what already exists? - [ ] better way to determine value type in
attributeChangedCallback?