Skip to content

Commit 3027ad7

Browse files
authored
fix: Avoid crashing playground example when typing layers, views etc (#192)
1 parent 04b4bde commit 3027ad7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

examples/playground/src/json-configuration.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// This configuration object determines which deck.gl classes are accessible in Playground
66

77
// deck.gl
8-
import {MapView, FirstPersonView, OrbitView, OrthographicView} from '@deck.gl/core';
8+
import {MapView, FirstPersonView, OrbitView, OrthographicView, View, Layer} from '@deck.gl/core';
99
import {COORDINATE_SYSTEM} from '@deck.gl/core';
1010
import * as Layers from '@deck.gl/layers';
1111
import * as AggregationLayers from '@deck.gl/aggregation-layers';
@@ -22,10 +22,7 @@ import {CSVLoader} from '@loaders.gl/csv';
2222
import {DracoWorkerLoader} from '@loaders.gl/draco';
2323
import {Tiles3DLoader, CesiumIonLoader} from '@loaders.gl/3d-tiles';
2424

25-
const LOADERS = [
26-
CSVLoader,
27-
DracoWorkerLoader
28-
]
25+
const LOADERS = [CSVLoader, DracoWorkerLoader];
2926

3027
// Note: deck already registers JSONLoader...
3128
registerLoaders(LOADERS);
@@ -52,7 +49,7 @@ export const JSON_CONFIGURATION = {
5249
// community layer modules
5350
...CommunityLayers,
5451
...EditableLayers,
55-
...GraphLayers,
52+
...GraphLayers
5653
// ArrowLayers,
5754
},
5855

@@ -62,12 +59,26 @@ export const JSON_CONFIGURATION = {
6259
// Enumerations that should be available to JSON parser
6360
// Will be resolved as `<enum-name>.<enum-value>`
6461
enumerations: {
65-
COORDINATE_SYSTEM,
62+
COORDINATE_SYSTEM
6663
},
6764

6865
// Constants that should be resolved with the provided values by JSON converter
6966
constants: {
7067
Tiles3DLoader,
7168
CesiumIonLoader
69+
},
70+
71+
postProcessConvertedJson: (json) => {
72+
// Filter out invalid props. Typically, props will be invalid while the user is typing.
73+
if (json.layers) {
74+
json.layers = json.layers.filter((layer) => layer instanceof Layer);
75+
}
76+
if (json.widgets) {
77+
json.widgets = json.widgets.filter((widget) => typeof widget.onAdd === 'function');
78+
}
79+
if (json.views && !(json.views instanceof View)) {
80+
json.views = json.views.filter((view) => view instanceof View);
81+
}
82+
return json;
7283
}
7384
};

0 commit comments

Comments
 (0)