From c1bbae73ea6f09eb0fa5857d71c835a32ffac985 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 3 Jan 2022 15:48:05 +0100 Subject: [PATCH] Avoid target update when non necessary --- src/style_manager/model/Property.js | 10 +++++++--- test/specs/style_manager/model/Properties.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/style_manager/model/Property.js b/src/style_manager/model/Property.js index 454dfb140..e1d14581c 100644 --- a/src/style_manager/model/Property.js +++ b/src/style_manager/model/Property.js @@ -31,9 +31,9 @@ export default class Property extends Model { const { em } = this; const sm = em.get('StyleManager'); 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 applyStyle = !opts.__up && !parentProp; const to = this.changedAttributes(); const from = keys(to).reduce((a, i) => { @@ -41,6 +41,10 @@ export default class Property extends Model { 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 }); applyStyle && this.__upTargetsStyle({ [name]: value }, opts); } @@ -184,7 +188,7 @@ export default class Property extends Model { } __getClearProps() { - return { value: '', status: '' }; + return { value: '' }; } /** diff --git a/test/specs/style_manager/model/Properties.js b/test/specs/style_manager/model/Properties.js index be02f1470..8e9cbd282 100644 --- a/test/specs/style_manager/model/Properties.js +++ b/test/specs/style_manager/model/Properties.js @@ -683,6 +683,7 @@ describe('StyleManager properties logic', () => { }); test('On clear removes all values', () => { + compTypeProp.addLayer(); compTypeProp.clear(); expect(compTypeProp.hasValue()).toBe(false); expect(compTypeProp.getLayers().length).toBe(0);