You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
519 B

/**
* Bind event when mounted or activated
*/
import { on, off } from '../utils/dom/event';
var uid = 0;
export function BindEventMixin(handler) {
var key = "binded_" + uid++;
function bind() {
if (!this[key]) {
handler.call(this, on, true);
this[key] = true;
}
}
function unbind() {
if (this[key]) {
handler.call(this, off, false);
this[key] = false;
}
}
return {
mounted: bind,
activated: bind,
deactivated: unbind,
beforeDestroy: unbind
};
}