index.js
function(root, depth, context, delta) {
        var i;
        var currentValue = context[depth];
        var isMulti = currentValue.constructor === Array;
        if(depth === context.length-1) {
            if(isMulti) {
                for(i=0; i<currentValue.length; i++) {
                    var curDelta = delta;
                    if(root[currentValue[i]] !== undefined) {
                        curDelta = mergeDeep(delta, root[currentValue[i]], true);
                    }
                    root[currentValue[i]] = curDelta;
                }
            } else {
                curDelta = delta;
                if(root[currentValue] !== undefined) {
                    curDelta = mergeDeep(delta, root[currentValue], true);
                }
                root[currentValue] = curDelta;
            }
            return;
        }
        if(isMulti){
            for(i=0; i<currentValue.length; i++) {
                if(root[currentValue[i]] === undefined) {
                    root[currentValue[i]] = {};
                }
                this._buildTreeHelper(root[currentValue[i]], depth+1, context, delta);
            }
        } else {
            if(root[currentValue] === undefined) {
                root[currentValue] = {};
            }
            this._buildTreeHelper(root[currentValue], depth+1, context, delta);
        }
    }
function(root, depth, context, delta) {
        var i;
        var currentValue = context[depth];
        var isMulti = currentValue.constructor === Array;
        if(depth === context.length-1) {
            if(isMulti) {
                for(i=0; i<currentValue.length; i++) {
                    var curDelta = delta;
                    if(root[currentValue[i]] !== undefined) {
                        curDelta = mergeDeep(delta, root[currentValue[i]], true);
                    }
                    root[currentValue[i]] = curDelta;
                }
            } else {
                curDelta = delta;
                if(root[currentValue] !== undefined) {
                    curDelta = mergeDeep(delta, root[currentValue], true);
                }
                root[currentValue] = curDelta;
            }
            return;
        }
        if(isMulti){
            for(i=0; i<currentValue.length; i++) {
                if(root[currentValue[i]] === undefined) {
                    root[currentValue[i]] = {};
                }
                this._buildTreeHelper(root[currentValue[i]], depth+1, context, delta);
            }
        } else {
            if(root[currentValue] === undefined) {
                root[currentValue] = {};
            }
            this._buildTreeHelper(root[currentValue], depth+1, context, delta);
        }
    }
function ( root , depth , context , delta ) { var i ; var currentValue = context [ depth ] ; var isMulti = currentValue . constructor === Array ; if ( depth === context . length - 1 ) { if ( isMulti ) { for ( i = 0 ; i < currentValue . length ; i ++ ) { var curDelta = delta ; if ( root [ currentValue [ i ] ] !== undefined ) { curDelta = mergeDeep ( delta , root [ currentValue [ i ] ] , true ) ; } root [ currentValue [ i ] ] = curDelta ; } } else { curDelta = delta ; if ( root [ currentValue ] !== undefined ) { curDelta = mergeDeep ( delta , root [ currentValue ] , true ) ; } root [ currentValue ] = curDelta ; } return ; } if ( isMulti ) { for ( i = 0 ; i < currentValue . length ; i ++ ) { if ( root [ currentValue [ i ] ] === undefined ) { root [ currentValue [ i ] ] = { } ; } this . _buildTreeHelper ( root [ currentValue [ i ] ] , depth + 1 , context , delta ) ; } } else { if ( root [ currentValue ] === undefined ) { root [ currentValue ] = { } ; } this . _buildTreeHelper ( root [ currentValue ] , depth + 1 , context , delta ) ; } }
Insert the given context and delta into the tree.
@param root {object}
@param depth {number}
@param context {array}
@param delta {object}
@private
Insert the given context and delta into the tree .