UNPKG

kepler.gl

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

41 lines (39 loc) 5.55 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getPropertyValueFromSchema = getPropertyValueFromSchema; exports.loadPropertiesOrApplySchema = loadPropertiesOrApplySchema; exports.savePropertiesOrApplySchema = savePropertiesOrApplySchema; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // SPDX-License-Identifier: MIT // Copyright contributors to the kepler.gl project /** * Recursively save / load value for state based on property keys, * if property[key] is another schema * Use is to get value to save * @param {Object} state - state to save * @param {Object} properties - properties schema * @returns {Object} - saved state */ function savePropertiesOrApplySchema(state, properties) { return getPropertyValueFromSchema('save', state, properties); } function loadPropertiesOrApplySchema(state, properties) { return getPropertyValueFromSchema('load', state, properties); } function getPropertyValueFromSchema(operation, state, properties) { return Object.keys(properties).reduce(function (accu, key) { return _objectSpread(_objectSpread({}, accu), key in state ? properties[key] ? // if it's another schema properties[key][operation] ? // call save or load properties[key][operation](state[key], state) : // if it's another property object getPropertyValueFromSchema(operation, state[key], properties[key]) : (0, _defineProperty2["default"])({}, key, state[key]) : {}); }, {}); } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJz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