12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- '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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
- function copyWith(obj, key, value) {
- var result = typeof key === 'number' ? [].concat(_toConsumableArray(obj)) : _extends({}, obj);
- result[key] = value;
- return result;
- }
- var cowValueModel = exports.cowValueModel = function cowValueModel() {
- for (var _len = arguments.length, keyDescriptions = Array(_len), _key = 0; _key < _len; _key++) {
- keyDescriptions[_key] = arguments[_key];
- }
- var keys = [];
- keyDescriptions.forEach(function (each) {
- if (typeof each === 'number') keys.push(each);else keys.push.apply(keys, _toConsumableArray(each.toString().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 : copyWith(x, key, modified);
- }
- var GET_SENTINEL = {};
- return function (obj) {
- var val = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GET_SENTINEL;
- return val === GET_SENTINEL ? keys.reduce(function () {
- var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var key = arguments[1];
- return x[key];
- }, obj) : setField(obj, 0, val);
- };
- };
|