-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Bug: angular.equals not symmetric given objects with non-enumerable properties #14853
Comments
(As mentioned several times) the Is there some part of Angular that is using |
I am not sure this feature can still be trusted if the underlying function behaves incorrectly in this use case. |
So, are you trying to deep-watch an expression which sometimes points to an object with enumerable properties and sometimes to an object with non-enumerable? It sounds confusing. |
There's no expected behaviour in the current implementation, but as the handling of non-enumerable properties are not guaranteed by the documentation of Specifically,
In reality, non-enumerable properties are not copied right now. If the implementation were to change to copy them, then the copies may not compare correctly with the original. |
Currently the way to ignore certain parties of a deep tree is to pass a function that returns the expression to be watched, i.e. $scope.$watch(() => $scope.foo.bar.baz, () => { ... }); I would be wary about changing Angular's core, as this would be a breaking change with potentially significant effects on some users' apps. IMO, this is a non-standard way to try to eke out perf benefits when there are already existing tricks. |
@billccn, this sounds like a documentation issue. The behavior of If it were to change in the future it would be a breaking change. So, this would only happen in a minor version update, be properly documented and would be expected to break things (that's what breaking changes do 😃). But I don't think it is likely to ever happen. If anyone is interested in updating the docs though, they would be more than welcome! 😃 |
This also improves the example a bit: - better code formatting - initialization of `form` to an empty object - avoid using `email`, which doesn't get coppied when invalid (and might confuse users) Fixes #14853
POC:
What the results of these should be are debatable but the last two should be at least symmetric. (Presumbly, both should return
false
to retain transitivity.)The use case of non-enumerable is I want to ignore certain deep/cyclical/non-important part of the tree from comparison when using
Scope.$watch(..., ..., true)
.The text was updated successfully, but these errors were encountered: