@@ -148,40 +148,66 @@ var TransitioningResource = Resource.extend({
148148 isError : Ember . computed . equal ( 'transitioning' , 'error' ) ,
149149
150150 replaceWith : function ( ) {
151+ //console.log('1 replaceWith', this.get('id'));
151152 this . _super . apply ( this , arguments ) ;
152153 this . transitioningChanged ( ) ;
153154 } ,
154155
156+ wasAdded : function ( ) {
157+ this . transitioningChanged ( ) ;
158+ } ,
159+
160+ wasRemoved : function ( ) {
161+ this . transitioningChanged ( ) ;
162+ } ,
163+
155164 pollDelayTimer : null ,
156165 pollTimer : null ,
157166 reservedKeys : [ 'pollDelayTimer' , 'pollTimer' , 'waitInterval' , 'waitTimeout' ] ,
158167 transitioningChanged : function ( ) {
159- //console.log('Transitioning changed', this.toString(), this.get('transitioning'), this.get('pollDelayTimer'),this.get('pollTimer'));
168+ //console.log('Transitioning changed', this.toString(), this.get('transitioning'), this.get('pollDelayTimer'), this.get('pollTimer'));
160169
161- clearTimeout ( this . get ( 'pollDelayTimer' ) ) ;
162- clearTimeout ( this . get ( 'pollTimer' ) ) ;
170+ if ( this . get ( 'transitioning' ) !== 'yes' || ! this . isInStore ( ) )
171+ {
172+ clearTimeout ( this . get ( 'pollDelayTimer' ) ) ;
173+ clearTimeout ( this . get ( 'pollTimer' ) ) ;
174+ return ;
175+ }
163176
164- if ( ! this . isInStore ( ) )
177+ if ( this . get ( 'pollDelayTimer' ) )
165178 {
166- //console.log('This resource is not in the store');
179+ // Already polling or waiting, just let that one finish
167180 return ;
168181 }
169182
183+
170184 var delay = this . constructor . pollTransitioningDelay ;
171185 var interval = this . constructor . pollTransitioningInterval ;
172186 if ( delay > 0 && interval > 0 && this . get ( 'transitioning' ) === 'yes' )
173187 {
174188 //console.log('Starting poll timer', this.toString());
175189 this . set ( 'pollDelayTimer' , setTimeout ( function ( ) {
176- //console.log('1 expired');
190+ //console.log('1 expired', this.toString() );
177191 this . transitioningPoll ( ) ;
178192 } . bind ( this ) , delay ) ) ;
179193 }
194+ else
195+ {
196+ //console.log('Not polling', this.toString());
197+ clearTimeout ( this . get ( 'pollDelayTimer' ) ) ;
198+ this . set ( 'pollDelayTimer' , null ) ;
199+ }
180200 } . observes ( 'transitioning' ) ,
181201
182202 transitioningPoll : function ( ) {
183- clearTimeout ( this . get ( 'pollTimer' ) ) ;
203+ var self = this ;
204+ function reset ( ) {
205+ clearTimeout ( self . get ( 'pollDelayTimer' ) ) ;
206+ self . set ( 'pollDelayTimer' , null ) ;
207+ }
184208
209+ clearTimeout ( this . get ( 'pollTimer' ) ) ;
210+ this . set ( 'pollTimer' , null ) ;
185211 //console.log('Checking', this.toString());
186212
187213 if ( this . get ( 'transitioning' ) !== 'yes' || ! this . isInStore ( ) )
@@ -196,10 +222,16 @@ var TransitioningResource = Resource.extend({
196222 {
197223 //console.log('Rescheduling', this.toString());
198224 this . set ( 'pollTimer' , setTimeout ( function ( ) {
199- //console.log('2 expired');
225+ //console.log('2 expired', this.toString() );
200226 this . transitioningPoll ( ) ;
201227 } . bind ( this ) , this . constructor . pollTransitioningInterval ) ) ;
202228 }
229+ else
230+ {
231+ reset ( ) ;
232+ }
233+ } ) . catch ( ( ) => {
234+ reset ( ) ;
203235 } ) ;
204236 } ,
205237
@@ -241,7 +273,7 @@ var TransitioningResource = Resource.extend({
241273
242274 waitForAction : function ( name ) {
243275 return this . _waitForTestFn ( function ( ) {
244- console . log ( 'waitForAction(' + name + '):' , this . hasAction ( name ) ) ;
276+ // console.log('waitForAction('+name+'):', this.hasAction(name));
245277 return this . hasAction ( name ) ;
246278 } , 'Wait for action=' + name ) ;
247279 } ,
0 commit comments