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

[email protected] @Prop observers dont match documentation #639

Open
wjaspers opened this issue Jun 10, 2020 · 0 comments
Open

[email protected] @Prop observers dont match documentation #639

wjaspers opened this issue Jun 10, 2020 · 0 comments
Assignees

Comments

@wjaspers
Copy link

wjaspers commented Jun 10, 2020

When I create a child component, the @Prop({attribute: 'overridden-attribute-name'}) isn't observed by the component as expected, causing stencil's element reuse feature to refuse a repaint.

Failing example:

export class Person () {
  constructor(public readonly isUsingStencil: boolean = false) {}
}

@Component({tag: 'parent-component'})
export class ParentComponent() {
private observedPerson: Person;

constructor() {
  this.observedPerson = new Person(false);

  // Wait 5 seconds, then update the person reference
  setTimeout(() => {
       this.observedPerson = new Person(true);
  }, 5000);
}

render() {
  <div>
     <child-component overridden-attribute-name={this.observedPerson} />
  </div>
}
}

@Component({tag: 'child-component', shadow: false})
export class ChildComponent() {
  @Prop({ attribute: 'overridden-attribute-name' }) person: Person;
  
  render() {
     if (this.person.isUsingStencil) {
        return ( <span>It looks like they use stencil</span> );
     }

     return ( <span>Consider switching to stencil</span> );
   }
}

Working example:

export class Person () {
  constructor(public readonly isUsingStencil: boolean = false) {}
}

@Component({tag: 'parent-component'})
export class ParentComponent() {
private observedPerson: Person;

constructor() {
  this.observedPerson = new Person(false);

  // Wait 5 seconds, then update the person reference
  setTimeout(() => {
       this.observedPerson = new Person(true);
  }, 5000);
}

render() {
  <div>
     <child-component person={this.observedPerson} />
  </div>
}
}

@Component({tag: 'child-component', shadow: false})
export class ChildComponent() {
   // NOTE: The attribute name HAS to match or render() wont be called again.
  @Prop({ attribute: 'person' }) person: Person;
  
  render() {
     if (this.person.isUsingStencil) {
        return ( <span>It looks like they use stencil</span> );
     }

     return ( <span>Consider switching to stencil</span> );
   }
}
@wjaspers wjaspers changed the title [email protected] @Prop observers dont match documentation [email protected] @Prop observers dont match documentation Jun 10, 2020
@rwaskiewicz rwaskiewicz self-assigned this Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants