Skip to content

Feature request: disallow explicit calls to lifecycle hooks #427

Closed
@lazarljubenovic

Description

@lazarljubenovic

Disallow code like

method() {
  this.ngOnDestroy()
}
ngOnDestroy() { /* cleanup code here */}

Instead, we should write something like

cleanup() { /* cleanup code here */}
method() {
  this.cleanup()
}
ngOnDestroy() {
  this.cleanup()
}

As Rob put it, "don't call your own hooks, because one day, you'll be debugging something and you'll be really confused why hooks are firing unexpectedly/out of order/whatever".

Thought it would be a nice addition to codelyzer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions