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

Use exposed equals inside watch and equals #5913

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ function equals(o1, o2) {
if (!isArray(o2)) return false;
if ((length = o1.length) == o2.length) {
for(key=0; key<length; key++) {
if (!equals(o1[key], o2[key])) return false;
if (!angular.equals(o1[key], o2[key])) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand? what is the motivation for this? so that you can customize the equals function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly! when i know that in my SPA there are a lot of comparisons of a specific type, i can create a better comparison for that type (that depends only on the minimum number of properties that object needs. and then use the proxy pattern to replace the equals so that it will perform better for my SPA

}
return true;
}
Expand All @@ -833,7 +833,7 @@ function equals(o1, o2) {
keySet = {};
for(key in o1) {
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
if (!equals(o1[key], o2[key])) return false;
if (!angular.equals(o1[key], o2[key])) return false;
keySet[key] = true;
}
for(key in o2) {
Expand Down
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
parentGet = $parse(attrs[attrName]);
if (parentGet.literal) {
compare = equals;
compare = angular.equals;
} else {
compare = function(a,b) { return a === b; };
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function $RootScopeProvider(){
if (watch) {
if ((value = watch.get(current)) !== (last = watch.last) &&
!(watch.eq
? equals(value, last)
? angular.equals(value, last)
: (typeof value == 'number' && typeof last == 'number'
&& isNaN(value) && isNaN(last)))) {
dirty = true;
Expand Down