[Dojo-interest] make tree._setPathAttr() return a dojo.Deferred

Simon Speich simon.speich at gmail.com
Sun Jun 27 10:17:52 EDT 2010


In case anyone is interested I think I found a working solution. You can
chain two Deferreds together simply by adding a function that will return a
Deferred to another Deferred’s callback chain!  For example:
var  def = new dojo.Deferred();
def.addCallback(function(){
     return new dojo.Deferred();
});
So translated to the _setPathAttr() method this would give:

_setPathAttr: function(/*Item[] || String[]*/ path){
	if(!path || !path.length){ return; }
	this._loadDeferred.addCallback(dojo.hitch(this, function(){
		if(!this.rootNode){
			console.debug("!this.rootNode");
			return;
		}
		if(path[0] !== this.rootNode.item && (dojo.isString(path[0]) && path[0] !=
this.model.getIdentity(this.rootNode.item))){
			console.error(this, ":path[0] doesn't match this.rootNode.item.  Maybe
you are using the wrong tree.");
			return;
		}
		path.shift();
		var node = this.rootNode;
		function advance(){
			var item = path.shift(),
				identity = dojo.isString(item) ? item : this.model.getIdentity(item);
			dojo.some(this._itemNodesMap[identity], function(n){
				if(n.getParent() == node){
					node = n;
					return true;
				}
				return false;
			});
			if(path.length){
				var def = this._expandNode(node);
				def.addCallback(dojo.hitch(this, advance));
				return def;
			}else{
				if(this.lastFocused != node){
					this.focusNode(node);
				}
			}
		}
		var def = this._expandNode(node);
		def.addCallback(dojo.hitch(this, advance));
		return def;
	}));
	return this._loadDeferred;
}
-- 
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/make-tree-setPathAttr-return-a-dojo-Deferred-tp921735p925643.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.


More information about the Dojo-interest mailing list