Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($compile): add isFirstChange() method to onChanges object #14323

Closed

Conversation

petebacondarwin
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Feature

What is the current behavior? (You can also link to an open issue here)

Fixes #14318

What is the new behavior (if this is a feature change)?

Adds isFirstChange() method to changes objects

Does this PR introduce a breaking change?

No - although there is now an extra onChanges call if items are not updated during the first digest since the bindings were defined.

Please check if the PR fulfills these requirements

Other information:

Closes #14318

@thorn0
Copy link
Contributor

thorn0 commented Mar 26, 2016

Is $onChanges called before or after $onInit?

@gkalpak
Copy link
Member

gkalpak commented Mar 26, 2016

@thorn0, before $onInit. Isn't that how ng2 does it as well ?

@petebacondarwin, LGTM (despite some whitespace inconsistencies 😛 )

@petebacondarwin
Copy link
Contributor Author

@thorn0 - it seems that A2 does it this way: https://angular.io/docs/ts/latest/api/core/OnChanges-interface.html

@gkalpak - it passes JSCS :-P

@petebacondarwin
Copy link
Contributor Author

@gkalpak - fixed the white-space incongruities

@thorn0
Copy link
Contributor

thorn0 commented Mar 26, 2016

it seems that A2 does it this way

Although it does (see a plunk), this order doesn't look reasonable to me. :) But that's an issue for the A2 project...

@petebacondarwin
Copy link
Contributor Author

@thorn0 - I think the idea is that you can choose to ignore this "pre-init" ngChanges by checking the isFirstChange() method. But maybe you are suggesting that they only added that BECAUSE it was too difficult to ensure that this first change hook was not called.

@thorn0
Copy link
Contributor

thorn0 commented Mar 26, 2016

I just have doubts about the idea of calling anything on a not fully initialized component. As for the initial call of $onChanges in general, I think it's a good thing. For example, for use cases when the component has 'calculated' properties that depend on bindings.

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

Successfully merging this pull request may close these issues.

$onChanges isn't called on the initialization of the component
4 participants