MCPcopy Create free account
hub / github.com/visgl/react-map-gl / updateSource

Function updateSource

modules/react-mapbox/src/components/source.ts:41–78  ·  view source on GitHub ↗
(source: AnySourceImplementation, props: SourceProps, prevProps: SourceProps)

Source from the content-addressed store, hash-verified

39
40/* eslint-disable complexity */
41function updateSource(source: AnySourceImplementation, props: SourceProps, prevProps: SourceProps) {
42 assert(props.id === prevProps.id, 'source id changed');
43 assert(props.type === prevProps.type, 'source type changed');
44
45 let changedKey = '';
46 let changedKeyCount = 0;
47
48 for (const key in props) {
49 if (key !== 'children' && key !== 'id' && !deepEqual(prevProps[key], props[key])) {
50 changedKey = key;
51 changedKeyCount++;
52 }
53 }
54
55 if (!changedKeyCount) {
56 return;
57 }
58
59 const type = props.type;
60
61 if (type === 'geojson') {
62 (source as GeoJSONSourceImplementation).setData(props.data);
63 } else if (type === 'image') {
64 (source as ImageSourceImplementation).updateImage({
65 url: props.url,
66 coordinates: props.coordinates
67 });
68 } else if ('setCoordinates' in source && changedKeyCount === 1 && changedKey === 'coordinates') {
69 source.setCoordinates((props as unknown as ImageSourceSpecification).coordinates);
70 } else if ('setUrl' in source && changedKey === 'url') {
71 source.setUrl((props as VectorSourceSpecification).url);
72 } else if ('setTiles' in source && changedKey === 'tiles') {
73 source.setTiles((props as VectorSourceSpecification).tiles);
74 } else {
75 // eslint-disable-next-line
76 console.warn(`Unable to update <Source> prop: ${changedKey}`);
77 }
78}
79/* eslint-enable complexity */
80
81export function Source(props: SourceProps) {

Callers 1

SourceFunction · 0.70

Calls 2

deepEqualFunction · 0.90
assertFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…