jianghh-canvas
Version:
canvas画板,支持笔写、手写、鼠标流畅绘图,自动保存,撤销重做
32 lines (31 loc) • 788 B
JavaScript
var o = Object.defineProperty;
var f = (i, s, t) => s in i ? o(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
var e = (i, s, t) => (f(i, typeof s != "symbol" ? s + "" : s, t), t);
class h {
constructor() {
e(this, "events");
this.events = {};
}
// 订阅事件
on(s, t) {
this.events[s] = this.events[s] || [], this.events[s].push(t);
}
// 发布事件
emit(s, ...t) {
this.events[s] && this.events[s].forEach((n) => {
n(...t);
});
}
// 取消订阅
off(s, t) {
this.events[s] && (this.events[s] = this.events[s].filter((n) => n !== t));
}
}
function c(i) {
const s = new h();
i.$on = s.on.bind(s), i.$emit = s.emit.bind(s), i.$off = s.off.bind(s);
}
export {
h as EventBus,
c as useEventBus
};