@@ -11,7 +11,7 @@ import CollapseTree, { SELECT_MODE } from '../../-private/collapse-tree';
1111import defaultTo from '../../-private/utils/default-to' ;
1212
1313import layout from './template' ;
14- import { assert } from '@ember/debug' ;
14+ import { assert , runInDebug } from '@ember/debug' ;
1515
1616/**
1717 The table body component. This component manages the main bulk of the rows of
@@ -258,12 +258,24 @@ export default Component.extend({
258258
259259 this . _updateCollapseTree ( ) ;
260260
261+ runInDebug ( ( ) => {
262+ let scheduleUpdate = ( this . _scheduleUpdate = ( ) => {
263+ run . scheduleOnce ( 'actions' , this , this . _updateDataTestRowCount ) ;
264+ } ) ;
265+ this . collapseTree . addObserver ( 'rows' , scheduleUpdate ) ;
266+ this . collapseTree . addObserver ( '[]' , scheduleUpdate ) ;
267+ } ) ;
268+
261269 assert (
262270 'You must create an {{ember-thead}} with columns before creating an {{ember-tbody}}' ,
263271 ! ! this . get ( 'unwrappedApi.columnTree' )
264272 ) ;
265273 } ,
266274
275+ _updateDataTestRowCount ( ) {
276+ this . set ( 'dataTestRowCount' , this . get ( 'collapseTree.length' ) ) ;
277+ } ,
278+
267279 // eslint-disable-next-line
268280 _updateCollapseTree : observer (
269281 'unwrappedApi.{sorts,sortFunction,compareFunction,sortEmptyLast}' ,
@@ -295,6 +307,10 @@ export default Component.extend({
295307 this . rowMetaCache . delete ( row ) ;
296308 }
297309
310+ runInDebug ( ( ) => {
311+ this . collapseTree . removeObserver ( 'rows' , this . _scheduleUpdate ) ;
312+ this . collapseTree . removeObserver ( '[]' , this . _scheduleUpdate ) ;
313+ } ) ;
298314 this . collapseTree . destroy ( ) ;
299315 } ,
300316
@@ -309,11 +325,6 @@ export default Component.extend({
309325 this . collapseTree . set ( 'rowMetaCache' , this . rowMetaCache ) ;
310326 this . collapseTree . set ( 'rows' , rows ) ;
311327
312- run . schedule ( 'actions' , ( ) => {
313- // eslint-disable-next-line ember-best-practices/no-side-effect-cp
314- this . set ( 'dataTestRowCount' , this . get ( 'wrappedRows.length' ) ) ; // eslint-disable-line ember/no-side-effects
315- } ) ;
316-
317328 return this . collapseTree ;
318329 } ) ,
319330
0 commit comments