michael@0: "use strict"; michael@0: michael@0: var nil = {} michael@0: var owns = ({}).hasOwnProperty michael@0: michael@0: function rebase(result, parent, delta) { michael@0: var key, current, previous, update michael@0: for (key in parent) { michael@0: if (owns.call(parent, key)) { michael@0: previous = parent[key] michael@0: update = owns.call(delta, key) ? delta[key] : nil michael@0: if (previous === null) continue michael@0: else if (previous === void(0)) continue michael@0: else if (update === null) continue michael@0: else if (update === void(0)) continue michael@0: else result[key] = previous michael@0: } michael@0: } michael@0: for (key in delta) { michael@0: if (owns.call(delta, key)) { michael@0: update = delta[key] michael@0: current = owns.call(result, key) ? result[key] : nil michael@0: if (current === update) continue michael@0: else if (update === null) continue michael@0: else if (update === void(0)) continue michael@0: else if (current === nil) result[key] = update michael@0: else if (typeof(update) !== "object") result[key] = update michael@0: else if (typeof(current) !== "object") result[key] = update michael@0: else result[key]= rebase({}, current, update) michael@0: } michael@0: } michael@0: michael@0: return result michael@0: } michael@0: michael@0: module.exports = rebase