Browse Source

Avoid property breaking in StyleManager without `property`. Fixes #1830

pull/1874/head
Artur Arseniev 7 years ago
parent
commit
23d0dcd2d7
  1. 13
      src/style_manager/model/Property.js
  2. 5
      src/utils/mixins.js

13
src/style_manager/model/Property.js

@ -1,4 +1,5 @@
import { isUndefined, isString } from 'underscore'; import { isUndefined, isString } from 'underscore';
import { capitalize } from 'utils/mixins';
const Property = require('backbone').Model.extend( const Property = require('backbone').Model.extend(
{ {
@ -42,17 +43,13 @@ const Property = require('backbone').Model.extend(
}, },
initialize(props = {}, opts = {}) { initialize(props = {}, opts = {}) {
const id = this.get('id');
const name = this.get('name'); const name = this.get('name');
!this.get('property') &&
this.set('property', (name || id).replace(/ /g, '-'));
const prop = this.get('property'); const prop = this.get('property');
!this.get('id') && this.set('id', prop); !this.get('id') && this.set('id', prop);
!name && this.set('name', capitalize(prop).replace(/-/g, ' '));
if (!name) {
this.set(
'name',
prop.charAt(0).toUpperCase() + prop.slice(1).replace(/-/g, ' ')
);
}
Property.callInit(this, props, opts); Property.callInit(this, props, opts);
}, },

5
src/utils/mixins.js

@ -137,6 +137,8 @@ const getPointerEvent = ev =>
const getKeyCode = ev => ev.which || ev.keyCode; const getKeyCode = ev => ev.which || ev.keyCode;
const getKeyChar = ev => String.fromCharCode(getKeyCode(ev)); const getKeyChar = ev => String.fromCharCode(getKeyCode(ev));
const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1);
export { export {
on, on,
off, off,
@ -151,5 +153,6 @@ export {
shallowDiff, shallowDiff,
normalizeFloat, normalizeFloat,
getPointerEvent, getPointerEvent,
getUnitFromValue getUnitFromValue,
capitalize
}; };

Loading…
Cancel
Save