diff --git a/src/common/module.js b/src/common/module.js index 9c5995c73..7d7d56742 100644 --- a/src/common/module.js +++ b/src/common/module.js @@ -30,7 +30,7 @@ export default { this.em = this.config.em; }, - __initListen() { + __initListen(opts = {}) { const { all, em, events } = this; all && em && @@ -41,6 +41,16 @@ export default { em.trigger(events.update, p, p.changedAttributes(), c) ) .on('all', this.__catchAllEvent, this); + // Register collections + this.cls = [all].concat(opts.collections || []); + // Propagate events + (opts.propagate || []).forEach(({ entity, event }) => { + entity.on('all', (ev, model, coll, opts) => { + const options = opts || coll; + const opt = { event: ev, ...options }; + [em, all].map(md => md.trigger(event, model, opt)); + }); + }); }, __remove(model, opts = {}) { @@ -88,5 +98,13 @@ export default { } while (allMap[id]); return id; + }, + + __destroy() { + this.cls.forEach(coll => { + coll.stopListening(); + coll.reset(); + }); + this.em = 0; } }; diff --git a/src/selector_manager/index.js b/src/selector_manager/index.js index fb0011f03..79062632e 100644 --- a/src/selector_manager/index.js +++ b/src/selector_manager/index.js @@ -44,7 +44,7 @@ * * `selector:add` - Selector added. The [Selector] is passed as an argument to the callback. * * `selector:remove` - Selector removed. The [Selector] is passed as an argument to the callback. * * `selector:update` - Selector updated. The [Selector] and the object containing changes are passed as arguments to the callback. - * * `selector:state` - State changed. Passes the new state value as an argument. + * * `selector:state` - States changed. An object containing all the available data about the triggered event is passed as an argument to the callback. * * `selector` - Catch-all event for all the events mentioned above. An object containing all the available data about the triggered event is passed as an argument to the callback. * * ## Methods @@ -134,13 +134,9 @@ export default () => { em.trigger('selector:type', value) ); const listenTo = - 'component:toggled component:update:classes styleManager:update change:state selector:type'; + 'component:toggled component:update:classes styleManager:update selector:state selector:type'; this.model.listenTo(em, listenTo, () => this.__update()); - em.on(this.events.all, (...args) => { - console.log('All event', args); - }); - return this; }, @@ -409,12 +405,9 @@ export default () => { destroy() { const { selectorTags, model } = this; - const all = this.getAll(); model.stopListening(); - all.stopListening(); - all.reset(); + this.__destroy(); selectorTags && selectorTags.remove(); - this.em = {}; this.selectorTags = {}; }, diff --git a/src/selector_manager/model/State.js b/src/selector_manager/model/State.js index a79a12821..81036cf6a 100644 --- a/src/selector_manager/model/State.js +++ b/src/selector_manager/model/State.js @@ -26,7 +26,7 @@ export default class State extends Model { * @returns {String} */ getLabel() { - return this.get('label'); + return this.get('label') || this.getName(); } } diff --git a/src/selector_manager/view/ClassTagsView.js b/src/selector_manager/view/ClassTagsView.js index fd8f7cac8..b0779ac9c 100644 --- a/src/selector_manager/view/ClassTagsView.js +++ b/src/selector_manager/view/ClassTagsView.js @@ -3,15 +3,7 @@ import Backbone from 'backbone'; import ClassTagView from './ClassTagView'; export default Backbone.View.extend({ - template({ - labelInfo, - labelStates, - labelHead, - iconSync, - iconAdd, - pfx, - ppfx - }) { + template({ labelInfo, labelHead, iconSync, iconAdd, pfx, ppfx }) { return `