@@ -1052,8 +1052,7 @@ function $ParseProvider() {
1052
1052
parsedExpression = wrapSharedExpression ( parsedExpression ) ;
1053
1053
parsedExpression . $$watchDelegate = parsedExpression . literal ?
1054
1054
oneTimeLiteralWatchDelegate : oneTimeWatchDelegate ;
1055
- }
1056
- else if ( parsedExpression . inputs ) {
1055
+ } else if ( parsedExpression . inputs ) {
1057
1056
parsedExpression . $$watchDelegate = inputsWatchDelegate ;
1058
1057
}
1059
1058
@@ -1075,8 +1074,7 @@ function $ParseProvider() {
1075
1074
if ( ! input . constant ) {
1076
1075
if ( input . inputs ) {
1077
1076
collectExpressionInputs ( input . inputs , list ) ;
1078
- }
1079
- else if ( - 1 === list . indexOf ( input ) ) {
1077
+ } else if ( list . indexOf ( input ) === - 1 ) { // TODO(perf) can we do better?
1080
1078
list . push ( input ) ;
1081
1079
}
1082
1080
}
@@ -1089,21 +1087,18 @@ function $ParseProvider() {
1089
1087
if ( o1 == null || o2 == null ) return o1 === o2 ; // null/undefined
1090
1088
1091
1089
if ( typeof o1 === "object" ) {
1092
- //The same object is not supported because it may have been mutated
1090
+ // The same object is not supported because it may have been mutated
1093
1091
if ( o1 === o2 ) return false ;
1094
1092
1095
1093
if ( typeof o2 !== "object" ) return false ;
1096
1094
1097
- //Dates
1098
- if ( isDate ( o1 ) && isDate ( o2 ) ) {
1095
+ // Dates
1096
+ if ( isDate ( o1 ) && isDate ( o2 ) ) { // TODO(perf): make this more generic via valueOf
1099
1097
o1 = o1 . getTime ( ) ;
1100
1098
o2 = o2 . getTime ( ) ;
1101
-
1102
- //Fallthru to the primitive equality check
1103
- }
1104
-
1105
- //Otherwise objects are not supported - recursing over arrays/object would be too expensive
1106
- else {
1099
+ // Fallthru to the primitive equality check
1100
+ } else {
1101
+ // objects/arrays are not supported - deep-watching them would be too expensive
1107
1102
return false ;
1108
1103
}
1109
1104
}
@@ -1116,29 +1111,33 @@ function $ParseProvider() {
1116
1111
var inputExpressions = parsedExpression . $$inputs ||
1117
1112
( parsedExpression . $$inputs = collectExpressionInputs ( parsedExpression . inputs , [ ] ) ) ;
1118
1113
1119
- var inputs = [ simpleEquals /*=something that will never equal an evaluated input*/ ] ;
1120
1114
var lastResult ;
1121
1115
1122
- if ( 1 === inputExpressions . length ) {
1123
- inputs = inputs [ 0 ] ;
1116
+ if ( inputExpressions . length === 1 ) {
1117
+ var oldInputValue = simpleEquals ; // init to something unique so that equals check fails
1124
1118
inputExpressions = inputExpressions [ 0 ] ;
1125
1119
return scope . $watch ( function expressionInputWatch ( scope ) {
1126
- var newVal = inputExpressions ( scope ) ;
1127
- if ( ! simpleEquals ( newVal , inputs ) ) {
1120
+ var newInputValue = inputExpressions ( scope ) ;
1121
+ if ( ! simpleEquals ( newInputValue , oldInputValue ) ) {
1128
1122
lastResult = parsedExpression ( scope ) ;
1129
- inputs = newVal ;
1123
+ oldInputValue = newInputValue ;
1130
1124
}
1131
1125
return lastResult ;
1132
1126
} , listener , objectEquality ) ;
1133
1127
}
1134
1128
1129
+ var oldInputValues = [ ] ;
1130
+ for ( var i = 0 , ii = inputExpressions . length ; i < ii ; i ++ ) {
1131
+ oldInputValues [ i ] = simpleEquals ; // init to something unique so that equals check fails
1132
+ }
1133
+
1135
1134
return scope . $watch ( function expressionInputsWatch ( scope ) {
1136
1135
var changed = false ;
1137
1136
1138
- for ( var i = 0 , ii = inputExpressions . length ; i < ii ; i ++ ) {
1139
- var valI = inputExpressions [ i ] ( scope ) ;
1140
- if ( changed || ( changed = ! simpleEquals ( valI , inputs [ i ] ) ) ) {
1141
- inputs [ i ] = valI ;
1137
+ for ( var i = 0 , ii = inputExpressions . length ; i < ii ; i ++ ) {
1138
+ var newInputValue = inputExpressions [ i ] ( scope ) ;
1139
+ if ( changed || ( changed = ! simpleEquals ( newInputValue , oldInputValues [ i ] ) ) ) {
1140
+ oldInputValues [ i ] = newInputValue ;
1142
1141
}
1143
1142
}
1144
1143
0 commit comments