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 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 () => {
var c = {};
let properties;
@ -65,11 +70,12 @@ export default () => {
PropertyFactory: PropertyFactory(),
/**
* Name of the module
* @type {String}
* @private
*/
events: {
all: evAll,
propertyUpdate: evPropUp,
custom: evCustom
},
name: 'StyleManager',
/**
@ -101,13 +107,21 @@ export default () => {
toListen,
debounce((...args) => {
this.select(em.getSelectedAll());
em.trigger('style:custom');
this.__trgCustom();
})
);
return this;
},
__trgCustom() {
this.em.trigger(this.events.custom);
},
__trgEv(event, ...data) {
this.em.trigger(event, ...data);
},
onLoad() {
// Use silent as sectors' view will be created and rendered on StyleManager.render
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 value = this.getFullValue();
const changed = this.changedAttributes();
const previous = keys(changed).reduce((a, i) => {
const to = this.changedAttributes();
const from = keys(to).reduce((a, i) => {
a[i] = this.previous(i);
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 });
}

Loading…
Cancel
Save