@@ -168,6 +168,23 @@ test("it maps properties", function() {
168168 deepEqual ( get ( obj , 'mapped' ) , [ 1 , 3 , 2 , 5 ] ) ;
169169} ) ;
170170
171+ test ( "it is observerable" , function ( ) {
172+ var mapped = get ( obj , 'mapped' ) ,
173+ calls = 0 ;
174+
175+ deepEqual ( get ( obj , 'mapped' ) , [ 1 , 3 , 2 , 1 ] ) ;
176+
177+ Ember . addObserver ( obj , 'mapped.@each' , function ( ) {
178+ calls ++ ;
179+ } ) ;
180+
181+ Ember . run ( function ( ) {
182+ obj . get ( 'array' ) . pushObject ( { v : 5 } ) ;
183+ } ) ;
184+
185+ equal ( calls , 1 , 'Ember.computed.mapBy is observerable' ) ;
186+ } ) ;
187+
171188
172189module ( 'Ember.computed.filter' , {
173190 setup : function ( ) {
@@ -1100,7 +1117,6 @@ test("filtering, sorting and reduce (max) can be combined", function() {
11001117 equal ( 35 , get ( obj , 'oldestStarkAge' ) , "chain is updated correctly" ) ;
11011118} ) ;
11021119
1103-
11041120function todo ( name , priority ) {
11051121 return Ember . Object . create ( { name : name , priority : priority } ) ;
11061122}
@@ -1160,3 +1176,43 @@ test("it can filter and sort when both depend on the same item property", functi
11601176 deepEqual ( sorted . mapProperty ( 'name' ) , [ 'A' , 'B' , 'C' , 'E' , 'D' ] , "precond - sorted updated correctly" ) ;
11611177 deepEqual ( filtered . mapProperty ( 'name' ) , [ 'A' , 'C' , 'E' , 'D' ] , "filtered updated correctly" ) ;
11621178} ) ;
1179+
1180+ module ( 'Chaining array and reduced CPs' , {
1181+ setup : function ( ) {
1182+ Ember . run ( function ( ) {
1183+ userFnCalls = 0 ;
1184+ obj = Ember . Object . createWithMixins ( {
1185+ array : Ember . A ( [ { v : 1 } , { v : 3 } , { v : 2 } , { v : 1 } ] ) ,
1186+ mapped : Ember . computed . mapBy ( 'array' , 'v' ) ,
1187+ max : Ember . computed . max ( 'mapped' ) ,
1188+ maxDidChange : Ember . observer ( function ( ) {
1189+ userFnCalls ++ ;
1190+ } , 'max' )
1191+ } ) ;
1192+ } ) ;
1193+ } ,
1194+ teardown : function ( ) {
1195+ Ember . run ( function ( ) {
1196+ obj . destroy ( ) ;
1197+ } ) ;
1198+ }
1199+ } ) ;
1200+
1201+ test ( "it computes interdependent array computed properties" , function ( ) {
1202+ var mapped = get ( obj , 'mapped' ) ;
1203+
1204+ equal ( get ( obj , 'max' ) , 3 , 'sanity - it properly computes the maximum value' ) ;
1205+ equal ( userFnCalls , 0 , 'observer is not called on initialisation' ) ;
1206+
1207+ var calls = 0 ;
1208+ Ember . addObserver ( obj , 'max' , function ( ) { calls ++ ; } ) ;
1209+
1210+ Ember . run ( function ( ) {
1211+ obj . get ( 'array' ) . pushObject ( { v : 5 } ) ;
1212+ } ) ;
1213+
1214+ equal ( get ( obj , 'max' ) , 5 , 'maximum value is updated correctly' ) ;
1215+ equal ( userFnCalls , 1 , 'object defined observers fire' ) ;
1216+ equal ( calls , 1 , 'runtime created observers fire' ) ;
1217+ } ) ;
1218+
0 commit comments