1
+ /*eslint no-use-before-define:0*/
1
2
var modelsEqual = function ( obj1 , obj2 ) {
2
3
if ( ! obj1 && ! obj2 )
3
4
return true ;
@@ -8,33 +9,39 @@ var modelsEqual = function(obj1, obj2) {
8
9
return obj1 . id === obj2 . id ;
9
10
} ;
10
11
11
- var compareArrays = function ( arr1 , arr2 , compFunc ) {
12
- if ( arr1 === arr2 ) {
12
+ var arrayIsEqual = function ( arr , other , deep ) {
13
+ // if the other array is a falsy value, return
14
+ if ( ! arr && ! other ) {
13
15
return true ;
14
16
}
15
- if ( ! arr1 ) {
16
- arr1 = [ ] ;
17
- }
18
- if ( ! arr2 ) {
19
- arr2 = [ ] ;
17
+
18
+ if ( ! arr || ! other ) {
19
+ return false ;
20
20
}
21
21
22
- if ( arr1 . length != arr2 . length ) {
22
+ // compare lengths - can save a lot of time
23
+ if ( arr . length != other . length ) {
23
24
return false ;
24
25
}
25
26
26
- for ( var i = 0 ; i < Math . max ( arr1 . length , arr2 . length ) ; i ++ ) {
27
- if ( ! arr1 [ i ] ) {
28
- return false ;
29
- }
30
- if ( ! arr2 [ i ] ) {
31
- return false ;
27
+ for ( var i = 0 , l = Math . max ( arr . length , other . length ) ; i < l ; i ++ ) {
28
+ return valueIsEqual ( arr [ i ] , other [ i ] , deep ) ;
29
+ }
30
+ } ;
31
+
32
+ var valueIsEqual = function ( value , other , deep ) {
33
+ if ( value === other ) {
34
+ return true ;
35
+ } else if ( value instanceof Array || other instanceof Array ) {
36
+ if ( arrayIsEqual ( value , other , deep ) ) {
37
+ return true ;
32
38
}
33
- if ( ! compFunc ( arr1 [ i ] , arr2 [ i ] ) ) {
34
- return false ;
39
+ } else if ( value instanceof Object || other instanceof Object ) {
40
+ if ( objectMatchesSubset ( value , other , deep ) ) {
41
+ return true ;
35
42
}
36
43
}
37
- return true ;
44
+ return false ;
38
45
} ;
39
46
40
47
var objectMatchesSubset = function ( obj , other , deep ) {
@@ -57,39 +64,33 @@ var objectMatchesSubset = function(obj, other, deep){
57
64
return true ;
58
65
} ;
59
66
60
- var valueIsEqual = function ( value , other , deep ) {
61
- if ( value === other ) {
67
+ var compareArrays = function ( arr1 , arr2 , compFunc ) {
68
+ if ( arr1 === arr2 ) {
62
69
return true ;
63
- } else if ( value instanceof Array || other instanceof Array ) {
64
- if ( arrayIsEqual ( value , other , deep ) ) {
65
- return true ;
66
- }
67
- } else if ( value instanceof Object || other instanceof Object ) {
68
- if ( objectMatchesSubset ( value , other , deep ) ) {
69
- return true ;
70
- }
71
70
}
72
- return false ;
73
- } ;
74
-
75
- var arrayIsEqual = function ( arr , other , deep ) {
76
- // if the other array is a falsy value, return
77
- if ( ! arr && ! other ) {
78
- return true ;
71
+ if ( ! arr1 ) {
72
+ arr1 = [ ] ;
79
73
}
80
-
81
- if ( ! arr || ! other ) {
82
- return false ;
74
+ if ( ! arr2 ) {
75
+ arr2 = [ ] ;
83
76
}
84
77
85
- // compare lengths - can save a lot of time
86
- if ( arr . length != other . length ) {
78
+ if ( arr1 . length != arr2 . length ) {
87
79
return false ;
88
80
}
89
81
90
- for ( var i = 0 , l = Math . max ( arr . length , other . length ) ; i < l ; i ++ ) {
91
- return valueIsEqual ( arr [ i ] , other [ i ] , deep ) ;
82
+ for ( var i = 0 ; i < Math . max ( arr1 . length , arr2 . length ) ; i ++ ) {
83
+ if ( ! arr1 [ i ] ) {
84
+ return false ;
85
+ }
86
+ if ( ! arr2 [ i ] ) {
87
+ return false ;
88
+ }
89
+ if ( ! compFunc ( arr1 [ i ] , arr2 [ i ] ) ) {
90
+ return false ;
91
+ }
92
92
}
93
+ return true ;
93
94
} ;
94
95
95
96
export default {
@@ -190,4 +191,3 @@ export default {
190
191
StreamManager : require ( './utils/streamManager' ) ,
191
192
CursorPoller : require ( './utils/cursorPoller' )
192
193
} ;
193
-
0 commit comments