Browse Source

Propagate property update

up-style-manager
Artur Arseniev 5 years ago
parent
commit
843a161de5
  1. 26
      src/style_manager/index.js
  2. 6
      src/style_manager/model/Property.js

26
src/style_manager/index.js

@ -53,6 +53,11 @@ import Properties from './model/Properties';
import PropertyFactory from './model/PropertyFactory'; import PropertyFactory from './model/PropertyFactory';
import SectorsView from './view/SectorsView'; import SectorsView from './view/SectorsView';
export const evAll = 'style';
export const evPfx = `${evAll}:`;
export const evPropUp = `${evPfx}property:update`;
export const evCustom = `${evPfx}custom`;
export default () => { export default () => {
var c = {}; var c = {};
let properties; let properties;
@ -65,11 +70,12 @@ export default () => {
PropertyFactory: PropertyFactory(), PropertyFactory: PropertyFactory(),
/** events: {
* Name of the module all: evAll,
* @type {String} propertyUpdate: evPropUp,
* @private custom: evCustom
*/ },
name: 'StyleManager', name: 'StyleManager',
/** /**
@ -101,13 +107,21 @@ export default () => {
toListen, toListen,
debounce((...args) => { debounce((...args) => {
this.select(em.getSelectedAll()); this.select(em.getSelectedAll());
em.trigger('style:custom'); this.__trgCustom();
}) })
); );
return this; return this;
}, },
__trgCustom() {
this.em.trigger(this.events.custom);
},
__trgEv(event, ...data) {
this.em.trigger(event, ...data);
},
onLoad() { onLoad() {
// Use silent as sectors' view will be created and rendered on StyleManager.render // Use silent as sectors' view will be created and rendered on StyleManager.render
sectors.add(c.sectors, { silent: true }); sectors.add(c.sectors, { silent: true });

6
src/style_manager/model/Property.js

@ -23,13 +23,13 @@ export default class Property extends Model {
const name = this.getName(); const name = this.getName();
const value = this.getFullValue(); const value = this.getFullValue();
const changed = this.changedAttributes(); const to = this.changedAttributes();
const previous = keys(changed).reduce((a, i) => { const from = keys(to).reduce((a, i) => {
a[i] = this.previous(i); a[i] = this.previous(i);
return a; return a;
}, {}); }, {});
console.log('Update targets', { name, value, changed, previous, opts });
sm.__trgEv(sm.events.propertyUpdate, { property: this, from, to });
!opts.__up && sm.addStyleTargets({ [name]: value }); !opts.__up && sm.addStyleTargets({ [name]: value });
} }

Loading…
Cancel
Save