Browse Source

Avoid target update when non necessary

up-style-manager
Artur Arseniev 4 years ago
parent
commit
c1bbae73ea
  1. 10
      src/style_manager/model/Property.js
  2. 1
      test/specs/style_manager/model/Properties.js

10
src/style_manager/model/Property.js

@ -31,9 +31,9 @@ export default class Property extends Model {
const { em } = this; const { em } = this;
const sm = em.get('StyleManager'); const sm = em.get('StyleManager');
const name = this.getName(); const name = this.getName();
const value = opts.__clear ? '' : this.__getFullValue(opts); const isClear = opts.__clear;
const value = isClear ? '' : this.__getFullValue(opts);
const parentProp = this.__getParentProp(); const parentProp = this.__getParentProp();
const applyStyle = !opts.__up && !parentProp;
const to = this.changedAttributes(); const to = this.changedAttributes();
const from = keys(to).reduce((a, i) => { const from = keys(to).reduce((a, i) => {
@ -41,6 +41,10 @@ export default class Property extends Model {
return a; return a;
}, {}); }, {});
const kProps = keys(this.__getClearProps());
const toProps = keys(to);
const applyStyle = !opts.__up && !parentProp && (isClear || kProps.some(k => toProps.indexOf(k) >= 0));
sm.__trgEv(sm.events.propertyUpdate, { property: this, from, to, value, opts }); sm.__trgEv(sm.events.propertyUpdate, { property: this, from, to, value, opts });
applyStyle && this.__upTargetsStyle({ [name]: value }, opts); applyStyle && this.__upTargetsStyle({ [name]: value }, opts);
} }
@ -184,7 +188,7 @@ export default class Property extends Model {
} }
__getClearProps() { __getClearProps() {
return { value: '', status: '' }; return { value: '' };
} }
/** /**

1
test/specs/style_manager/model/Properties.js

@ -683,6 +683,7 @@ describe('StyleManager properties logic', () => {
}); });
test('On clear removes all values', () => { test('On clear removes all values', () => {
compTypeProp.addLayer();
compTypeProp.clear(); compTypeProp.clear();
expect(compTypeProp.hasValue()).toBe(false); expect(compTypeProp.hasValue()).toBe(false);
expect(compTypeProp.getLayers().length).toBe(0); expect(compTypeProp.getLayers().length).toBe(0);

Loading…
Cancel
Save