From 1f1a919c77107eb04586b179e7b6cdcc5504b4a6 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Thu, 29 Dec 2016 22:00:49 +0100 Subject: [PATCH] Only update style if it is valid --- src/components/App.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 0f0aecd..f45c832 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -10,6 +10,8 @@ import LayerEditor from './layers/LayerEditor' import Toolbar from './Toolbar' import AppLayout from './AppLayout' +import GlSpec from 'mapbox-gl-style-spec/reference/latest.js' +import validateStyleMin from 'mapbox-gl-style-spec/lib/validate_style.min' import style from '../libs/style.js' import { loadDefaultStyle, StyleStore } from '../libs/stylestore' import { ApiStyleStore } from '../libs/apistore' @@ -71,9 +73,14 @@ export default class App extends React.Component { } onStyleChanged(newStyle) { - this.revisionStore.addRevision(newStyle) - this.saveStyle(newStyle) - this.setState({ mapStyle: newStyle }) + const errors = validateStyleMin(newStyle, GlSpec) + if(errors.length === 0) { + this.revisionStore.addRevision(newStyle) + this.saveStyle(newStyle) + this.setState({ mapStyle: newStyle }) + } else { + errors.forEach(err => console.error(err.message)) + } } onUndo() {