From ed87425f01e95b91e5644ae9b09dc341dfe97272 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Tue, 20 Dec 2016 14:50:38 +0100 Subject: [PATCH] Switch away from Immutable JS for layer editor --- src/components/App.jsx | 6 ++-- src/components/fields/ColorField.jsx | 8 +++-- src/components/fields/PropertyGroup.jsx | 12 +++++--- src/components/layers/LayerEditor.jsx | 40 ++++++++++++++----------- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index d3c2b22..f09fa60 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -1,4 +1,5 @@ import React from 'react' +import Immutable from 'immutable' import { saveAs } from 'file-saver' import Drawer from 'rebass/dist/Drawer' @@ -99,7 +100,7 @@ export default class App extends React.Component { } onLayerChanged(layer) { - const changedStyle = this.state.mapStyle.setIn(['layers', layer.get('id')], layer) + const changedStyle = this.state.mapStyle.setIn(['layers', layer.id], Immutable.fromJS(layer)) this.onStyleChanged(changedStyle) } @@ -125,6 +126,7 @@ export default class App extends React.Component { render() { const selectedLayer = this.state.mapStyle.getIn(['layers', this.state.selectedLayerId], null) + return
- {selectedLayer && } + {selectedLayer && }
{this.mapRenderer()} diff --git a/src/components/fields/ColorField.jsx b/src/components/fields/ColorField.jsx index a7bd721..7ed34d6 100644 --- a/src/components/fields/ColorField.jsx +++ b/src/components/fields/ColorField.jsx @@ -15,7 +15,6 @@ class ColorField extends React.Component { onChange: React.PropTypes.func.isRequired, name: React.PropTypes.string.isRequired, value: React.PropTypes.string, - default: React.PropTypes.number, doc: React.PropTypes.string, style: React.PropTypes.object, } @@ -31,14 +30,19 @@ class ColorField extends React.Component { this.setState({ pickerOpened: !this.state.pickerOpened }) } + get color() { + return Color(this.props.value || '#fff') + } + render() { + console.log(Color(this.props.value)) const picker =
this.props.onChange(formatColor(c))} />
{ - const fieldSpec = getFieldSpec(this.props.layer.get('type'), fieldName) - const fieldValue = this.props.layer.getIn(['paint', fieldName], this.props.layer.getIn(['layout', fieldName])) + const fieldSpec = getFieldSpec(this.props.layer.type, fieldName) + + const paint = this.props.layer.paint || {} + const layout = this.props.layer.layout || {} + const fieldValue = paint[fieldName] || layout[fieldName] + return { return }) - console.log(this.props.layer.toJSON()) let visibleIcon = - if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') { + if('layout' in this.props.layer && this.props.layer.layout.visibility === 'none') { visibleIcon = } return
- {this.props.layer.get('id')} + {this.props.layer.id} @@ -114,14 +120,14 @@ export default class LayerEditor extends React.Component { {propertyGroups} this.onFilterChange(Immutable.fromJS(f))} /> - {this.props.layer.get('type') !== 'background' + {this.props.layer.type !== 'background' &&