Skip to content

Commit

Permalink
fix: throw an error if layer or source props is not an Immutable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Jan 17, 2019
1 parent 10c41f6 commit a43b320
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/clickable-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ initialState = {
}
};

const onClick = (event) => {
const onClick = event => {
const feature = event.features[0];
if (!feature) return;

Expand All @@ -55,13 +55,13 @@ const onClick = (event) => {
};

<MapGL
style={{ width: "100%", height: "400px" }}
mapStyle="mapbox://styles/mapbox/light-v9"
style={{ width: '100%', height: '400px' }}
mapStyle='mapbox://styles/mapbox/light-v9'
accessToken={MAPBOX_ACCESS_TOKEN}
{...state.viewport}
>
<Source id='markers' source={state.sources.get('markers')} />
<Layer layer={state.layers.get('markers')} onClick={onClick} />
<Layer layer={state.layers.get('highlighted-marker')} />
</MapGL>
```
</MapGL>;
```
5 changes: 5 additions & 0 deletions src/components/Layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class Layer extends PureComponent<Props> {

constructor(props: Props) {
super(props);

if (!isImmutable(props.layer)) {
throw new Error('Provided layer prop is not an Immutable object');
}

this._id = props.id || props.layer.get('id', '');
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/Source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class Source extends PureComponent<Props> {

static displayName = 'Source';

constructor(props: Props) {
super(props);

if (!isImmutable(props.source)) {
throw new Error('Provided source prop is not an Immutable object');
}
}

componentDidMount() {
const { id, source } = this.props;
this._map.addSource(id, source.toJS());
Expand Down

0 comments on commit a43b320

Please sign in to comment.