Skip to content

Component inheritance #172

@cjorasch

Description

@cjorasch

Resources:
Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

@stencil/core@0.0.5-17

I'm submitting a ... (check one with "x")
[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
If a component extends another component then the props, state, etc. are not inheritted.

Expected behavior:
It should be possible to extend a component and have the derived component inherit the base class features (Prop, State, etc.).

This is the behavior with Ionic v3 using Angular so existing apps would break when moving to Ionic v4.

One use case for inheritance is a base component with all of the logic (properties, event handling, etc.) and derived implementations with alternate rendering methods. For example, a component that can render with Bootstrap markup on the web and Ionic markup in an app.

Related code:

@Component({
  tag: 'test-hello',
})
export class Hello {
  @Prop() name: string;
  render() {
    return (
      <div>
        Hello {this.name}.
      </div>
    );
  }
}

@Component({
  tag: 'test-goodbye',
})
export class Goodbye extends Hello {

  render() {
    return (
      <div>
        Goodbye {this.name}.
      </div>
    );
  }
}

<test-hello name="John" />
<test-goodbye name="John" />

Produces the following output:

Hello John.
Goodbye .

Metadata

Metadata

Assignees

Labels

Awaiting ReplyThis PR or Issue needs a reply from the original reporter.ionitron: stale issueThis issue has not seen any activity for a long period of time

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions