From 26ee4991b06f76a89f4c2df6c9e919c6fb038d1e Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 8 Jan 2022 07:50:50 +0100 Subject: [PATCH] Add style sector events --- src/common/module.js | 20 +++++++++++++++----- src/style_manager/index.js | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/common/module.js b/src/common/module.js index ba5784ad2..0dc72f99e 100644 --- a/src/common/module.js +++ b/src/common/module.js @@ -25,7 +25,7 @@ export default { __initConfig(def = {}, conf = {}) { this.config = { ...def, - ...conf + ...conf, }; this.em = this.config.em; }, @@ -37,9 +37,7 @@ export default { all .on('add', (m, c, o) => em.trigger(events.add, m, o)) .on('remove', (m, c, o) => em.trigger(events.remove, m, o)) - .on('change', (p, c) => - em.trigger(events.update, p, p.changedAttributes(), c) - ) + .on('change', (p, c) => em.trigger(events.update, p, p.changedAttributes(), c)) .on('all', this.__catchAllEvent, this); // Register collections this.cls = [all].concat(opts.collections || []); @@ -100,11 +98,23 @@ export default { return id; }, + __listenAdd(model, event) { + model.on('add', (m, c, o) => this.em.trigger(event, m, o)); + }, + + __listenRemove(model, event) { + model.on('remove', (m, c, o) => this.em.trigger(event, m, o)); + }, + + __listenUpdate(model, event) { + model.on('change', (p, c) => this.em.trigger(event, p, p.changedAttributes(), c)); + }, + __destroy() { this.cls.forEach(coll => { coll.stopListening(); coll.reset(); }); this.em = 0; - } + }, }; diff --git a/src/style_manager/index.js b/src/style_manager/index.js index 2855589f2..ee3151565 100644 --- a/src/style_manager/index.js +++ b/src/style_manager/index.js @@ -21,6 +21,10 @@ * ``` * ## Available Events * * `style:sector:add` - Sector added. The [Sector] is passed as an argument to the callback. + * * `style:sector:remove` - Sector removed. The [Sector] is passed as an argument to the callback. + * * `style:sector:update` - Sector updated. The [Sector] and the object containing changes are passed as arguments to the callback. + * + * * `style:sector:add` - Sector added. The [Sector] is passed as an argument to the callback. * * `style:target` - Target selection changed. The target (or `null` in case the target is deselected) is passed as an argument to the callback. * * `styleManager:update:target` - The target (Component or CSSRule) is changed * * `styleManager:change` - Triggered on style property change from new selected component, the view of the property is passed as an argument to the callback @@ -69,6 +73,10 @@ import SectorsView from './view/SectorsView'; export const evAll = 'style'; export const evPfx = `${evAll}:`; +export const evSector = `${evPfx}sector`; +export const evSectorAdd = `${evSector}:add`; +export const evSectorRemove = `${evSector}:remove`; +export const evSectorUpdate = `${evSector}:update`; export const evPropUp = `${evPfx}property:update`; export const evLayerSelect = `${evPfx}layer:select`; export const evTarget = `${evPfx}target`; @@ -87,6 +95,9 @@ export default () => { events: { all: evAll, + sectorAdd: evSectorAdd, + sectorRemove: evSectorRemove, + sectorUpdate: evSectorUpdate, propertyUpdate: evPropUp, layerSelect: evLayerSelect, target: evTarget, @@ -118,6 +129,9 @@ export default () => { sectors = new Sectors([], { ...c, module: this }); const model = new Model({ targets: [] }); this.model = model; + this.__listenAdd(sectors, evSectorAdd); + this.__listenRemove(sectors, evSectorRemove); + this.__listenUpdate(sectors, evSectorUpdate); // Triggers for the selection refresh and properties const ev = 'component:toggled component:update:classes change:state change:device frame:resized selector:type';