Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile JSX to custom element (proof of concept) #83

Closed
thescientist13 opened this issue Aug 3, 2022 Discussed in #69 · 0 comments · Fixed by #73 or #93
Closed

Compile JSX to custom element (proof of concept) #83

thescientist13 opened this issue Aug 3, 2022 Discussed in #69 · 0 comments · Fixed by #73 or #93
Assignees
Labels
documentation Improvements or additions to documentation feature New feature or request JSX v0.6.0
Milestone

Comments

@thescientist13
Copy link
Member

Discussed in #69

Originally posted by thescientist13 June 26, 2022
In thinking about a different approach, what if #66 was explored through JSX? 🤔

JSX is similar to tagged template literals, but per my understanding, doesn't prescribe a specific implementation. So perhaps this could be used to provide an (optional) development experience, through a render function, that can take JSX and the compiler can unwind that into valid custom element lifecycles. So no VDOM here, it would just be vanilla JS.

# input
class Counter extends HTMLElement {
  constructor() {
    this.count = 0;
  }

  dec() {
    this.count -= 1;
  }
  
  inc() {
    this.count += 1;
  }

  render() {
    const count = this;
   
    return (
      <button click={this.dec}>-</span>
      <span>{count}</span>
      <button click={this.inc}>+</span>      
    )
  }
}
# output
class Counter extends HTMLElement {
  constructor() {
    this.count = 0;
  }

  static get observedAttributes() { 
    return ['count'];
  }

  set count() {
    this.render();
  }
  
  dec() {
    this.count -= 1;
  }
  
  inc() {
    this.count += 1;
  }

  render() {
    const count = this;
   
    return `
      <button click=${this.dec}>-</span>
      <span>${count}</span>
      <button click=${this.inc}>+</span>      
    `;
  }
}

Or something like that, the devil is in details and so will want to play around with it, but think I can probably get a prototype whipped up.

Some useful links / references:

Perhaps this is something built into #29 ?

@thescientist13 thescientist13 added feature New feature or request JSX v0.6.0 labels Aug 3, 2022
@thescientist13 thescientist13 self-assigned this Aug 3, 2022
@thescientist13 thescientist13 linked a pull request Aug 3, 2022 that will close this issue
31 tasks
@thescientist13 thescientist13 added this to the 1.0 milestone Aug 3, 2022
@thescientist13 thescientist13 added the documentation Improvements or additions to documentation label Aug 3, 2022
@thescientist13 thescientist13 changed the title Compile JSX to custom element Compile JSX to custom element (proof of concept) Aug 3, 2022
@thescientist13 thescientist13 pinned this issue Aug 9, 2022
@thescientist13 thescientist13 linked a pull request Aug 13, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or request JSX v0.6.0
Projects
None yet
1 participant