Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Remove the need to keep implementing life cycle classes on subclasses #19

Closed
frankpepermans opened this issue Jul 27, 2016 · 8 comments
Closed
Milestone

Comments

@frankpepermans
Copy link

frankpepermans commented Jul 27, 2016

Currently you can extend existing components or directives, but in order for the life cycle hooks to trigger, the subclass must always copy the 'implements' list.

i.e.

@Component()
class Foo implements OnDestroy {
    void ngOnDestroy() => 'do something';
}
@Component()
class Bar extends Foo implements OnDestroy {
    // ngOnDestroy is called
}
@Component()
class Baz extends Foo {
    // ngOnDestroy is not called
}

Bar need to declare that it imlpements OnDestroy, or the ngOnDestroy method is not called.

I've always assumed that this was a downside from the compile-from-TS solution, is there any chance this can be adjusted? (ending up with the Baz class instead of the Bar class)

@matanlurey
Copy link
Contributor

So you definitely want the interface in Dart because you'll get static checks if you forget to implement the ngOnDestroy method and you can make a clean (component as OnDestroy).ngOnDestroy() call.

The one limitation today (we're working on it) is that if you inherit from a class that implements OnDestroy the lifecycle event is not called.

@matanlurey
Copy link
Contributor

Blocked by #48

@matanlurey
Copy link
Contributor

Just an update: Still blocked by #48 (same issue). Early work is getting us towards this.

@matanlurey matanlurey added this to the V4 Beta milestone Apr 4, 2017
@matanlurey
Copy link
Contributor

This is now planned for the 4.0 release.

@matanlurey
Copy link
Contributor

Good news, this is now unblocked and we are testing a fix internally.

@matanlurey
Copy link
Contributor

Blocked by #404.

@matanlurey
Copy link
Contributor

Closing since it technically has landed. It will be available in 4.0.0.

@erikhugintech
Copy link

This seems not to work if there's an extra class in between the component implementing life cycle classes and the class actually instantiated.

class Base implements OnInit
class Intermediate extends Base
class TheComponent extends Intermediate

ngOnInit call is not generated for TheComponent.

class Base implements OnInit
class Intermediate extends Base implements OnInit
class TheComponent extends Intermediate

Now ngOnInit call is generated for TheComponent.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants