@@ -2840,6 +2840,46 @@ describe('parser', function() {
2840
2840
expect ( filterCalled ) . toBe ( true ) ;
2841
2841
} ) ;
2842
2842
2843
+ it ( 'should not be invoked unless the input/arguments change within literals' , function ( ) {
2844
+ var filterCalls = [ ] ;
2845
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
2846
+ filterCalls . push ( input ) ;
2847
+ return input ;
2848
+ } ) ) ;
2849
+
2850
+ scope . $watch ( '[(a | foo:b:1), undefined]' ) ;
2851
+ scope . a = 0 ;
2852
+ scope . $digest ( ) ;
2853
+ expect ( filterCalls ) . toEqual ( [ 0 ] ) ;
2854
+
2855
+ scope . $digest ( ) ;
2856
+ expect ( filterCalls ) . toEqual ( [ 0 ] ) ;
2857
+
2858
+ scope . a ++ ;
2859
+ scope . $digest ( ) ;
2860
+ expect ( filterCalls ) . toEqual ( [ 0 , 1 ] ) ;
2861
+ } ) ;
2862
+
2863
+ it ( 'should not be invoked unless the input/arguments change within literals (one-time)' , function ( ) {
2864
+ var filterCalls = [ ] ;
2865
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
2866
+ filterCalls . push ( input ) ;
2867
+ return input ;
2868
+ } ) ) ;
2869
+
2870
+ scope . $watch ( '::[(a | foo:b:1), undefined]' ) ;
2871
+ scope . a = 0 ;
2872
+ scope . $digest ( ) ;
2873
+ expect ( filterCalls ) . toEqual ( [ 0 ] ) ;
2874
+
2875
+ scope . $digest ( ) ;
2876
+ expect ( filterCalls ) . toEqual ( [ 0 ] ) ;
2877
+
2878
+ scope . a ++ ;
2879
+ scope . $digest ( ) ;
2880
+ expect ( filterCalls ) . toEqual ( [ 0 , 1 ] ) ;
2881
+ } ) ;
2882
+
2843
2883
it ( 'should always be invoked if they are marked as having $stateful' , function ( ) {
2844
2884
var filterCalled = false ;
2845
2885
$filterProvider . register ( 'foo' , valueFn ( extend ( function ( input ) {
@@ -2883,6 +2923,52 @@ describe('parser', function() {
2883
2923
expect ( watcherCalls ) . toBe ( 1 ) ;
2884
2924
} ) ) ;
2885
2925
2926
+ it ( 'should ignore changes within nested objects' , function ( ) {
2927
+ var watchCalls = [ ] ;
2928
+ scope . $watch ( '[a]' , function ( a ) { watchCalls . push ( a [ 0 ] ) ; } ) ;
2929
+ scope . a = 0 ;
2930
+ scope . $digest ( ) ;
2931
+ expect ( watchCalls ) . toEqual ( [ 0 ] ) ;
2932
+
2933
+ scope . $digest ( ) ;
2934
+ expect ( watchCalls ) . toEqual ( [ 0 ] ) ;
2935
+
2936
+ scope . a ++ ;
2937
+ scope . $digest ( ) ;
2938
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 ] ) ;
2939
+
2940
+ scope . a = { } ;
2941
+ scope . $digest ( ) ;
2942
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 , { } ] ) ;
2943
+
2944
+ scope . a . foo = 42 ;
2945
+ scope . $digest ( ) ;
2946
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 , { foo : 42 } ] ) ;
2947
+ } ) ;
2948
+
2949
+ it ( 'should ignore changes within nested objects (one-time)' , function ( ) {
2950
+ var watchCalls = [ ] ;
2951
+ scope . $watch ( '::[a, undefined]' , function ( a ) { watchCalls . push ( a [ 0 ] ) ; } ) ;
2952
+ scope . a = 0 ;
2953
+ scope . $digest ( ) ;
2954
+ expect ( watchCalls ) . toEqual ( [ 0 ] ) ;
2955
+
2956
+ scope . $digest ( ) ;
2957
+ expect ( watchCalls ) . toEqual ( [ 0 ] ) ;
2958
+
2959
+ scope . a ++ ;
2960
+ scope . $digest ( ) ;
2961
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 ] ) ;
2962
+
2963
+ scope . a = { } ;
2964
+ scope . $digest ( ) ;
2965
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 , { } ] ) ;
2966
+
2967
+ scope . a . foo = 42 ;
2968
+ scope . $digest ( ) ;
2969
+ expect ( watchCalls ) . toEqual ( [ 0 , 1 , { foo : 42 } ] ) ;
2970
+ } ) ;
2971
+
2886
2972
describe ( 'with non-primitive input' , function ( ) {
2887
2973
2888
2974
describe ( 'that does NOT support valueOf()' , function ( ) {
0 commit comments