From a43b320d1560dcb9b49a7278e3a2f29c31ba97e5 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Thu, 17 Jan 2019 13:06:44 +0300 Subject: [PATCH] fix: throw an error if layer or source props is not an Immutable objects --- docs/clickable-map.md | 10 +++++----- src/components/Layer/index.js | 5 +++++ src/components/Source/index.js | 8 ++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/clickable-map.md b/docs/clickable-map.md index e4abd544..13984b0d 100644 --- a/docs/clickable-map.md +++ b/docs/clickable-map.md @@ -42,7 +42,7 @@ initialState = { } }; -const onClick = (event) => { +const onClick = event => { const feature = event.features[0]; if (!feature) return; @@ -55,13 +55,13 @@ const onClick = (event) => { }; - -``` \ No newline at end of file +; +``` diff --git a/src/components/Layer/index.js b/src/components/Layer/index.js index c24237d5..955472c7 100644 --- a/src/components/Layer/index.js +++ b/src/components/Layer/index.js @@ -88,6 +88,11 @@ class Layer extends PureComponent { 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', ''); } diff --git a/src/components/Source/index.js b/src/components/Source/index.js index 0538caee..75b987c5 100644 --- a/src/components/Source/index.js +++ b/src/components/Source/index.js @@ -18,6 +18,14 @@ class Source extends PureComponent { 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());