static-content/DeepUtils.js
function(target, skeleton) {
//            console.log("Applying change: "+JSON.stringify(skeleton));
            if (skeleton == null) {
                return false;
            }
            if (typeof skeleton != typeof target) {
                return false;
            }
            switch (typeof skeleton)
            {
                case 'string':
                case 'number':
                case 'boolean':
                    // gone too far
                    return false;
                case 'object':
                    if (skeleton instanceof Array)
                    {
                        // for now only support direct replacement/mutation of elements, skeleton is insufficient to describe splicing
                        if (target.length != skeleton.length) {
                            return false;
                        }
                        var changed = false;
                        for (var i=0; i<skeleton.length; i++) {
                            if (skeleton[i] == null) {
                                continue;
                            }
                            switch (typeof skeleton[i]) {
                                case 'string':
                                case 'number':
                                case 'boolean':
                                    changed = (target[i] != skeleton[i]) || changed;
                                    target[i] = skeleton[i];
                                    break;
                                case 'object':
                                    changed = deepApply(target[i], skeleton[i]) || changed;
                                    break;
                                default:
                                    throw 'Unrecognized type: '+(typeof skeleton[i]);
                            }
                        }
                        return changed;
                    }
                    else {
                        var changed = false;
                        for (var k in skeleton) {
                            if (skeleton.hasOwnProperty(k)) {
                                if (target.hasOwnProperty(k)) {
                                    if (skeleton[k] == null) {
                                        continue;
                                    }
                                    switch (typeof skeleton[k]) {
                                        case 'string':
                                        case 'number':
                                        case 'boolean':
                                            changed = target[k] != skeleton[k] || changed;
                                            target[k] = skeleton[k];
                                            break;
                                        case 'object':
                                            changed = deepApply(target[k], skeleton[k]) || changed;
                                            break;
                                        default:
                                            throw 'Unrecognized type: '+(typeof skeleton[k]);
                                    }
                                }
                                else {
                                    target[k] = skeleton[k];
                                }
                            }
                        }
                        return changed;
                    }
                    break;
                default:
                    throw 'Unrecognized type: '+(typeof incoming);
            }
        }
function(target, skeleton) {
//            console.log("Applying change: "+JSON.stringify(skeleton));
            if (skeleton == null) {
                return false;
            }
            if (typeof skeleton != typeof target) {
                return false;
            }
            switch (typeof skeleton)
            {
                case 'string':
                case 'number':
                case 'boolean':
                    // gone too far
                    return false;
                case 'object':
                    if (skeleton instanceof Array)
                    {
                        // for now only support direct replacement/mutation of elements, skeleton is insufficient to describe splicing
                        if (target.length != skeleton.length) {
                            return false;
                        }
                        var changed = false;
                        for (var i=0; i<skeleton.length; i++) {
                            if (skeleton[i] == null) {
                                continue;
                            }
                            switch (typeof skeleton[i]) {
                                case 'string':
                                case 'number':
                                case 'boolean':
                                    changed = (target[i] != skeleton[i]) || changed;
                                    target[i] = skeleton[i];
                                    break;
                                case 'object':
                                    changed = deepApply(target[i], skeleton[i]) || changed;
                                    break;
                                default:
                                    throw 'Unrecognized type: '+(typeof skeleton[i]);
                            }
                        }
                        return changed;
                    }
                    else {
                        var changed = false;
                        for (var k in skeleton) {
                            if (skeleton.hasOwnProperty(k)) {
                                if (target.hasOwnProperty(k)) {
                                    if (skeleton[k] == null) {
                                        continue;
                                    }
                                    switch (typeof skeleton[k]) {
                                        case 'string':
                                        case 'number':
                                        case 'boolean':
                                            changed = target[k] != skeleton[k] || changed;
                                            target[k] = skeleton[k];
                                            break;
                                        case 'object':
                                            changed = deepApply(target[k], skeleton[k]) || changed;
                                            break;
                                        default:
                                            throw 'Unrecognized type: '+(typeof skeleton[k]);
                                    }
                                }
                                else {
                                    target[k] = skeleton[k];
                                }
                            }
                        }
                        return changed;
                    }
                    break;
                default:
                    throw 'Unrecognized type: '+(typeof incoming);
            }
        }
function ( target , skeleton ) { //            console.log("Applying change: "+JSON.stringify(skeleton)); if ( skeleton == null ) { return false ; } if ( typeof skeleton != typeof target ) { return false ; } switch ( typeof skeleton ) { case 'string' : case 'number' : case 'boolean' : // gone too far return false ; case 'object' : if ( skeleton instanceof Array ) { // for now only support direct replacement/mutation of elements, skeleton is insufficient to describe splicing if ( target . length != skeleton . length ) { return false ; } var changed = false ; for ( var i = 0 ; i < skeleton . length ; i ++ ) { if ( skeleton [ i ] == null ) { continue ; } switch ( typeof skeleton [ i ] ) { case 'string' : case 'number' : case 'boolean' : changed = ( target [ i ] != skeleton [ i ] ) || changed ; target [ i ] = skeleton [ i ] ; break ; case 'object' : changed = deepApply ( target [ i ] , skeleton [ i ] ) || changed ; break ; default : throw 'Unrecognized type: ' + ( typeof skeleton [ i ] ) ; } } return changed ; } else { var changed = false ; for ( var k in skeleton ) { if ( skeleton . hasOwnProperty ( k ) ) { if ( target . hasOwnProperty ( k ) ) { if ( skeleton [ k ] == null ) { continue ; } switch ( typeof skeleton [ k ] ) { case 'string' : case 'number' : case 'boolean' : changed = target [ k ] != skeleton [ k ] || changed ; target [ k ] = skeleton [ k ] ; break ; case 'object' : changed = deepApply ( target [ k ] , skeleton [ k ] ) || changed ; break ; default : throw 'Unrecognized type: ' + ( typeof skeleton [ k ] ) ; } } else { target [ k ] = skeleton [ k ] ; } } } return changed ; } break ; default : throw 'Unrecognized type: ' + ( typeof incoming ) ; } }
Deep applies a skeleton change to the target object
Deep applies a skeleton change to the target object