From 23d0dcd2d7bab079afc5b972d4d3bd3a53c1907d Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 3 Mar 2019 15:15:25 +0100 Subject: [PATCH] Avoid property breaking in StyleManager without `property`. Fixes #1830 --- src/style_manager/model/Property.js | 13 +++++-------- src/utils/mixins.js | 5 ++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/style_manager/model/Property.js b/src/style_manager/model/Property.js index b1903bf41..b0f4c40f1 100644 --- a/src/style_manager/model/Property.js +++ b/src/style_manager/model/Property.js @@ -1,4 +1,5 @@ import { isUndefined, isString } from 'underscore'; +import { capitalize } from 'utils/mixins'; const Property = require('backbone').Model.extend( { @@ -42,17 +43,13 @@ const Property = require('backbone').Model.extend( }, initialize(props = {}, opts = {}) { + const id = this.get('id'); const name = this.get('name'); + !this.get('property') && + this.set('property', (name || id).replace(/ /g, '-')); const prop = this.get('property'); !this.get('id') && this.set('id', prop); - - if (!name) { - this.set( - 'name', - prop.charAt(0).toUpperCase() + prop.slice(1).replace(/-/g, ' ') - ); - } - + !name && this.set('name', capitalize(prop).replace(/-/g, ' ')); Property.callInit(this, props, opts); }, diff --git a/src/utils/mixins.js b/src/utils/mixins.js index 77c9189fc..add8ac8bb 100644 --- a/src/utils/mixins.js +++ b/src/utils/mixins.js @@ -137,6 +137,8 @@ const getPointerEvent = ev => const getKeyCode = ev => ev.which || ev.keyCode; const getKeyChar = ev => String.fromCharCode(getKeyCode(ev)); +const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1); + export { on, off, @@ -151,5 +153,6 @@ export { shallowDiff, normalizeFloat, getPointerEvent, - getUnitFromValue + getUnitFromValue, + capitalize };