-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Conversation
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
@@ -2499,6 +2538,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
$exceptionHandler(e); | |||
} | |||
} | |||
if (isFunction(controllerInstance.$doCheck)) { | |||
controllerScope.$watch(function() { controllerInstance.$doCheck(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to manually track the remove watch function because we are after the point when we might swap out the controller for another instance. This watch will naturally be removed when the controller scope is destroyed.
f82d100
to
453d74f
Compare
One thing to note: In Angular 2, there is no "digest loop" (running until the values have stabilized, which means at least twice per digest cycle) and the change detection is "single pass". Since the change detection works differently in Angular 1, there can't be a 1-to-1 mapping of the behavior of In particular, the ng2 behavior could be mapped to two strategies in ng1:
This PR uses strategy (1), so currently the order of execution when there is a change is: What I am sceptical about, is that with the current ng1 implementation it will be possible to do changes that will be picked up in the current digest cycle and apps will work fine. In ng2, this won't be the case. In that sense, it might be more consistent if we implemented strategy (2) without invoking another digest. I am more like thinking load than proposing anything tbh... |
Although it is worth noting that in A2 it is not recommended to use both |
To be clear, my concern is not about |
As an aside here are two demos of A2 ngDoChanges: Date http://plnkr.co/edit/1d1rlm2efCP31MphBvsf?p=preview |
@gkalpak can you put a unit test (or demo) together to illustrate your concern in A1? |
Oh, I just disabled Prod Mode and see what you now mean... |
But even if we put the changes in |
@gkalpak as far as I understood the main constraint is that we should not be able to trigger changes outside the component in its doCheck hook (as it is in A2) while changes inside the component should work just as it's implemented in this request. Please correct me if I'm wrong. |
We can trigger digest on the component scope following the |
Partial digesting is a worrying topic... |
@mazzur I think you are correct in your assumption that we should not trigger changes outside - but I don't think that we can honour this in Angular 1 without doing dastardly stuff, like partial digests |
@@ -3872,6 +3872,51 @@ describe('$compile', function() { | |||
]); | |||
}); | |||
}); | |||
|
|||
it('should work if $doCheck is provided in the constructor', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test looks identical to the one I added above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test above assigns the methods on the prototype. This test defines them on the instance from inside the constructor.
(Note that while both work in ng1, in ng2 only the prototype will work.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha okay, thanks for explaining :)
So I think that we should go with this implementation but document the following divergences from Angular 2:
|
Except that if we document the 1st deviation (not being on the prototype), we should document it for all lifecycle hooks. |
Backuport ngDoCheck from Angular 2.
de17903
to
2dcbc4e
Compare
…er constructor Closes #14811
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change?
Please check if the PR fulfills these requirements
Other information: