123456789101112131415161718192021222324252627282930313233343536373839 |
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- var cowValueModel = exports.cowValueModel = function cowValueModel(key) {
- var keys = key.split('.');
- function setField() {
- var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var index = arguments[1];
- var val = arguments[2];
- if (index >= keys.length) return val;
- var key = keys[index],
- value = x[key],
- modified = setField(value, index + 1, val);
- return value === modified ? x : _extends({}, x, _defineProperty({}, key, modified));
- }
- return {
- key: key,
- get: function get(obj) {
- return keys.reduce(function () {
- var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var key = arguments[1];
- return x[key];
- }, obj);
- },
- set: function set(obj, val) {
- return setField(obj, 0, val);
- }
- };
- };
|