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

New custom-elements transform #2067

Open
manucorporat opened this issue Dec 7, 2019 · 2 comments
Open

New custom-elements transform #2067

manucorporat opened this issue Dec 7, 2019 · 2 comments
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through.

Comments

@manucorporat
Copy link
Contributor

manucorporat commented Dec 7, 2019

GOAL

  • Remove need for proxyInput()
  • Remove low-level metadata generation
  • Human friendlier output

Emit getter and setters

@Prop() car;

becomes:

get car() {
 return getValue(this, 'car');
}
set car(value) {
 setValue(this, 'car', value);
}

Optional, we could inline the call to the watchers inlined in the setter

Emit observedAttributes static getter

@Prop()str:string;
@Prop() nu: number;

becomes:

static get observedAttributes() {
 return ['str', 'nu'];

Inject super call in connectedCallback and disconnectedCallback

connectedCallback() {
  console.log('hola');
}

becomes:

connectedCallback() {
  super.connectedCallback();
 console.log('hola');
}

Reflected properties??

@Prop({reflect: true}) prop: string;
  • We could add this metadata as a aux static getter (like watchers)
  • We could transform the render function to render reflected props
  • We could deprecate reflect

Emit attributeChangedCallback()

  • A custom attributeChangedCallback needs to be emitted to map the attributes with the properties

Metadata for listeners?

  • Listeners could be created/removed directly in the generated connectedCallback/disconnectedCallback

Metadata for members

  • Could be passed down in setValue

Example

@Component({
tagName: 'my-cmp',
styleUrl: './style.css'
})
export class MyCmp {
  @Element() el: HTMLElement;
  @Prop() prop:  string;
  @Prop({reflect: true}) reflected: number;
  @Event() myEvent;


  @Listen('click')
  onClick() {
    console.log('click');
  }

  connectedCallback() {
    console.log('hello');
  }

  @Watch('prop')
  propDidChange(newValue, oldValue) {
     console.log(newValue, oldValue);
  }

  render() {
    return (
      <Host><p>{this.prop}</p>
   )
 }

becomes:

export class MyCmp extends HTMLElement {
  constructor() {
  super();
    __stencil_registerHost(this);
    this.myEvent = __stencil_createEvent('myEvent', 2);
  }
  get el() {
    return this;
  }
  get prop() {
    return __stencil_getValue(this, 'prop');
  }
  set prop(value) {
    const oldValue = __stencil_setValue(this, 'prop', value, 1 /*string*/);
    if (oldValue) {
      this.propDidChange(value, oldValue);
    }
  } 
  get reflected() {
    return __stencil_getValue(this, 'reflected');
  }
  set reflected(value) {
    __stencil_setValue(this, 'reflected', value, 2 /*number*/);
  } 

  onClick() {
    console.log('click');
  }

  connectedCallback() {
   __stencil_connectedCallback(this);
    registerEvents(this, [['click', 'onClick', 0]]);
    console.log('hello');
  }

  disconnectedCallback() {
   __stencil_disconnectedCallback(this);
  }

  propDidChange(newValue, oldValue) {
     console.log(newValue, oldValue);
  }

  render() {
    return (
      <Host reflected={this.reflected}><p>{this.prop}</p>
   )
 }
@ionitron-bot ionitron-bot bot added the triage label Dec 7, 2019
@romulocintra
Copy link
Contributor

romulocintra commented Dec 9, 2019

My concerns are :

  • “Inject super call in connectedCallback and disconnectedCallback” this won”t affect current stencil lifecycle ?

  • “ observedAttributes” and attrChangesCallback will affect the initial value of newValue being undefined on initial render? i don’t remember actual behaviour in stencil probably is not relevant.

@eriklharper
Copy link

Will this proposal eliminate the console warnings when trying to declare a reserved word attribute/property name like title?

@rwaskiewicz rwaskiewicz added the Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. label Jan 17, 2023
@ionitron-bot ionitron-bot bot removed the triage label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through.
Projects
None yet
Development

No branches or pull requests

4 participants