js/foundation/application/application.js in rsence-2.1.11 vs js/foundation/application/application.js in rsence-2.2.0

- old
+ new

@@ -92,11 +92,11 @@ }, /** = Description * Adds a view to the app, +HView+ defines an indentical structure for subviews. * - * Called from inside the +HView+ constructor and should be automatic for all + * Called from inside the +HView+ constructor and should be automatic for all * components that accept the +_parent+ parameter, usually the second argument, * after the +HRect+ instance. * * = Parameters * +_view+:: Usually +this+ inside +HView+ -derived components. @@ -127,11 +127,28 @@ * = Parameters * +_viewId+:: The view ID. * **/ removeView: function(_viewId){ - HSystem.views[_viewId].remove(); + if( typeof _viewId === 'object' ){ + console.log('warning, viewId not a number:',_viewId,', trying to call its remove method directly..'); + _viewId.remove(); + return this; + } + var + _view = HSystem.views[_viewId]; + if( _view ){ + if( _view['remove'] ){ + HSystem.views[_viewId].remove(); + } + else { + console.log('view does not have method "remove":',_view); + } + } + else { + console.log('tried to remove non-existent viewId:'+_viewId); + } }, /** = Description * Removes and destructs the view of the given +_viewId+. * @@ -164,35 +181,60 @@ * application itself. * **/ destroyAllViews: function(){ for(var i = 0; i < this.views.length; i++) { - HSystem.views[this.views[i]].die(); + try{ + HSystem.views[this.views[i]].die(); + } + catch(e){ + console.log('unable to destroy:',this.views[i]); + } } }, + renice: function(_priority){ + HSystem.reniceApp(this.appId,_priority); + }, /* Calls the idle method of each view. Don't extend this method. */ _pollViews: function(){ - var i, _viewId, _view; - for(i=0;i<this.views.length;i++){ - _viewId = this.views[i]; + this._pollViewsRecurse( this.views ); + }, + _pollViewsRecurse: function( _views ){ + var i = 0, _viewId, _view, _pollViews = []; + for( ; i < _views.length;i++){ + _viewId = _views[i]; _view = HSystem.views[_viewId]; - if((_view!==null)&&(_view['onIdle']!==undefined)){ - _view.onIdle(); + if( _view !== undefined && _view !== null && typeof _view === 'object' ){ + if( _view['idle'] !== undefined && typeof _view['idle'] === 'function' ){ + _view.idle(); + } + if( _view['onIdle'] !== undefined && typeof _view['onIdle'] === 'function' ){ + _view.onIdle(); + } + if( _view['hasAncestor'] !== undefined && typeof _view.hasAncestor === 'function' && _view.hasAncestor( HView ) ) { + if( _view.views && _view.views instanceof Array ){ + _pollViews.push( _view.views ); + } + } } } + while( _pollViews.length > 0 ){ + this._pollViewsRecurse( _pollViews.shift() ); + } }, /** Gets called by +HSystem+. It makes +onIdle+ extensions more failure * resistant. Do not extend. **/ _startIdle: function(){ var _this = this; HSystem.busyApps[ _this.appId ] = true; this._busyTimer = setTimeout( function(){ + _this.idle(); _this.onIdle(); _this._pollViews(); HSystem.busyApps[ _this.appId ] = false; }, 10 @@ -207,8 +249,9 @@ * Intended for "slow infinite loops". * **/ onIdle: function(){ /* Your code here */ - } + }, + idle: function(){} }); HApplication.implement(HValueResponder.nu());