-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I have two proposals to improve JSX functionaity:
- Allow saving DOM elements to
this. Lets use the wordreffor this since it's the closest analogy to React. So this:
class Counter {
constructor() {
this.head = (
<div>
Count: <span ref="counterSpan">0</span>
<button onClick={() => this.handleClick()}>Increment</button>
</div>
);
}
handleClick() {
const prev = parseInt(this.counterSpan.textContent);
this.counterSpan.textContent = `${prev + 1}`;
}
}Would be equivalent to this:
class Counter {
constructor() {
this.head = raw.div(
raw.text('Count: '),
this.counterSpan = raw.span(raw.text('0')),
raw.button(raw.text('Increment', raw.on('click', () => this.handleClick()))),
);
}
handleClick() {
const prev = parseInt(this.counterSpan.textContent);
this.counterSpan.textContent = `${prev + 1}`;
}
}- If the tag's name starts with a capital letter, use a class from the local scope that defines the
headattribute. So this:
class App {
constructor() {
this.head = (
<div>
<h1>My awesome app</h1>
<Counter />
</div>
);
}
}Would be equivalent to this:
class App {
constructor() {
this.head = raw.div(
raw.h1(raw.text('My awesome app')),
(new Counter()).head,
);
}
}Metadata
Metadata
Assignees
Labels
No labels