[improvement] add bind event mixin

This commit is contained in:
陈嘉涵
2019-06-03 17:46:14 +08:00
parent 884f624a16
commit 616db0114e
4 changed files with 56 additions and 82 deletions

View File

@@ -0,0 +1,24 @@
import { on, off } from '../utils/event';
export function BindEventMixin(handler) {
function bind() {
if (!this.binded) {
handler.call(this, on);
this.binded = true;
}
}
function unbind() {
if (this.binded) {
handler.call(this, off);
this.binded = false;
}
}
return {
mounted: bind,
activated: bind,
destroyed: unbind,
deactivated: unbind
};
}