Added destroy lifecycle method

This commit is contained in:
Kevin Malakoff
2015-09-30 01:44:00 -07:00
parent 1539bba290
commit ff71c92b11

View File

@@ -20,6 +20,14 @@ class Clipboard extends Emitter {
this.delegateClick(selector); this.delegateClick(selector);
} }
/**
* @param {String} selector
* @param {Object} options
*/
destroy() {
this.undelegateClick();
}
/** /**
* Defines if attributes would be resolved using internal setter functions * Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor. * or custom functions that were passed in the constructor.
@@ -36,14 +44,22 @@ class Clipboard extends Emitter {
* @param {String} selector * @param {String} selector
*/ */
delegateClick(selector) { delegateClick(selector) {
Delegate.bind(document.body, selector, 'click', (e) => this.initialize(e)); Delegate.bind(document.body, selector, 'click', this.initialize);
}
/**
* Undelegates a click event on the passed selector.
* @param {String} selector
*/
undelegateClick() {
Delegate.unbind(document.body, 'click', this.initialize);
} }
/** /**
* Defines a new `ClipboardAction` on each click event. * Defines a new `ClipboardAction` on each click event.
* @param {Event} e * @param {Event} e
*/ */
initialize(e) { initialize = (e) => {
if (this.clipboardAction) { if (this.clipboardAction) {
this.clipboardAction = null; this.clipboardAction = null;
} }