nesquirk
Version:
Ties Nes + minimongo together for gloryful reactive apps.
38 lines (27 loc) • 782 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assign = undefined;
var _ejson = require('ejson');
var _ejson2 = _interopRequireDefault(_ejson);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function assign(obj, assignments) {
obj = _ejson2.default.clone(obj);
Object.keys(assignments).forEach(function (path) {
var splitPath = path.split('.');
var current = obj;
splitPath.forEach(function (prop, i) {
if (i === splitPath.length - 1) {
current[prop] = assignments[path];
return;
}
if (current[prop] == null) {
current[prop] = {};
}
current = current[prop];
});
});
return obj;
}
exports.assign = assign;