1. #1
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,232
    Vote Rating
    2
    mystix will become famous soon enough

      0  

    Default [2.0b1a][SOLVED] data.Node traversal when passing additional arguments?

    [2.0b1a][SOLVED] data.Node traversal when passing additional arguments?


    originally reported by @hendricd in this thread for Ext 1.1.x:
    http://www.sencha.com/forum/showthread.php?t=12555

    Quote Originally Posted by hendricd View Post
    Recently used the cascade methods of data.Node and discovered some odd behaviour with passing additional arguments. If additional arguments are passed, they 'call'ed rather than 'apply'ed, making for a confusing debug session. The arguments you specify are passed as an array of arguments rather than what might be expected elsewhere within the framework (fn.apply(scope,arguments)):

    Code:
    Ext.override(Ext.data.Node,{ 
    
        /**
         * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the bubble is stopped.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        bubble : function(fn, scope, args){
            var p = this;
            while(p){
    //          if(fn.call(scope || p, args || p) === false){
                if(fn.apply(scope || p, args || [p]) === false){
                    break;
                }
                p = p.parentNode;
            }
        },
    
        /**
         * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the cascade is stopped on that branch.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        cascade : function(fn, scope, args){
            //if(fn.call(scope || this, args || this) !== false){
            if(fn.apply(scope || this, args || [this]) !== false){
                var cs = this.childNodes;
                for(var i = 0, len = cs.length; i < len; i++) {
                	cs[i].cascade(fn, scope, args);
                }
            }
        },
    
        /**
         * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the iteration stops.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        eachChild : function(fn, scope, args){
            var cs = this.childNodes;
            for(var i = 0, len = cs.length; i < len; i++) {
                   //if(fn.call(scope || this, args || cs[i]) === false){
            	if(fn.apply(scope || this, args || [cs[i]]) === false){
            	    break;
            	}
            }
        }
    });
    By design ?

    re-reported in 2.x bugs on user request.

  2. #2
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,956
    Vote Rating
    8
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    And, Ext.Container:bubble, cascade have the same problem.

    Here are fixes for 2.0b+:

    Code:
    Ext.override(Ext.data.Tree,{ 
    
        /**
         * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the bubble is stopped.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        bubble : function(fn, scope, args){
            var p = this;
            while(p){
                if(fn.apply(scope || p, args || [p]) === false){
                    break;
                }
                p = p.parentNode;
            }
        },
    
        /**
         * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the cascade is stopped on that branch.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        cascade : function(fn, scope, args){
            if(fn.apply(scope || this, args || [this]) !== false){
                var cs = this.childNodes;
                for(var i = 0, len = cs.length; i < len; i++) {
                    cs[i].cascade(fn, scope, args);
                }
            }
        },
    
        /**
         * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the iteration stops.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        eachChild : function(fn, scope, args){
            var cs = this.childNodes;
            for(var i = 0, len = cs.length; i < len; i++) {
                if(fn.apply(scope || this, args || [cs[i]]) === false){
                    break;
                }
            }
        }
    });
    
    Ext.override (Ext.Container,{ 
      bubble : function(fn, scope, args){
            var p = this;
            while(p){
                if(fn.apply(scope || p, args || [p]) === false){
            //  if(fn.call(scope || p, args || p) === false){
                    break;
                }
                p = p.ownerCt;
            }
        },
    
      cascade : function(fn, scope, args){
          //if(fn.call(scope || this, args || this) !== false){
            if(fn.apply(scope || this, args || [this]) !== false){
               if(this.items){
                    var cs = this.items.items;
                    for(var i = 0, len = cs.length; i < len; i++){
                    
                        if(cs[i].cascade){
                            cs[i].cascade(fn, scope, args);
                        }
                    }
                }
            }
        }
    });
    [tags: cascade bubble eachChild parameters Container Tree]
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3
    Sencha - Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    26,166
    Vote Rating
    82
    jsakalos is a splendid one to behold jsakalos is a splendid one to behold jsakalos is a splendid one to behold jsakalos is a splendid one to behold jsakalos is a splendid one to behold jsakalos is a splendid one to behold jsakalos is a splendid one to behold

      0  

    Default


    Thank you for posting. We will take a look at it and we will inform you when fixed.

  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    6
    jack.slocum is on a distinguished road

      0  

    Default


    Will be fixed in next check in, thanks.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com