@deck.gl/json
Version:
JSON format rendering components for deck.gl
51 lines • 2.04 kB
JavaScript
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
// TODO - default parsing code should not be part of the configuration.
import parseExpressionString from "./helpers/parse-expression-string.js";
import assert from "./utils/assert.js";
import { TYPE_KEY, FUNCTION_KEY } from "./syntactic-sugar.js";
const isObject = value => value && typeof value === 'object';
export default class JSONConfiguration {
constructor(...configurations) {
this.typeKey = TYPE_KEY;
this.functionKey = FUNCTION_KEY;
this.log = console; // eslint-disable-line
this.classes = {};
this.reactComponents = {};
this.enumerations = {};
this.constants = {};
this.functions = {};
this.React = null;
// TODO - this needs to be simpler, function conversion should be built in
this.convertFunction = parseExpressionString;
this.preProcessClassProps = (Class, props) => props;
this.postProcessConvertedJson = json => json;
for (const configuration of configurations) {
this.merge(configuration);
}
}
merge(configuration) {
for (const key in configuration) {
switch (key) {
// DEPRECATED = For backwards compatibility, add views and layers to classes;
case 'layers':
case 'views':
Object.assign(this.classes, configuration[key]);
break;
default:
// Store configuration as root fields (this.classes, ...)
if (key in this) {
const value = configuration[key];
this[key] = isObject(this[key]) ? Object.assign(this[key], value) : value;
}
}
}
}
validate(configuration) {
assert(!this.typeKey || typeof this.typeKey === 'string');
assert(isObject(this.classes));
return true;
}
}
//# sourceMappingURL=json-configuration.js.map