Browse Source

Add `component:remove` event. Closes #748

pull/758/head
Artur Arseniev 8 years ago
parent
commit
013356b4ae
  1. 11
      src/dom_components/model/Component.js
  2. 1
      src/editor/index.js

11
src/dom_components/model/Component.js

@ -176,6 +176,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
this.config = opt.config || {};
this.ccid = Component.createId(this);
this.set('attributes', this.get('attributes') || {});
this.on('destroy', this.handleRemove);
this.listenTo(this, 'change:script', this.scriptUpdated);
this.listenTo(this, 'change:traits', this.traitsUpdated);
this.listenTo(this, 'change:tagName', this.tagUpdated);
@ -191,6 +192,16 @@ const Component = Backbone.Model.extend(Styleable).extend(
this.init();
},
/**
* Triggered on model remove
* @param {Model} removed Removed model
* @private
*/
handleRemove(removed) {
const em = this.em;
em && em.trigger('component:remove', removed);
},
/**
* Check component's type
* @param {string} type Component type

1
src/editor/index.js

@ -10,6 +10,7 @@
*
* ## Components
* * `component:add` - Triggered when a new component is added to the editor, the model is passed as an argument to the callback
* * `component:remove` - Triggered when a component is removed, the model is passed as an argument to the callback
* * `component:clone` - Triggered when a new component is added by a clone command, the model is passed as an argument to the callback
* * `component:update` - Triggered when a component is updated (moved, styled, etc.), the model is passed as an argument to the callback
* * `component:update:{propertyName}` - Listen any property change, the model is passed as an argument to the callback

Loading…
Cancel
Save