1 | import { EVENT_DISABLE, EVENT_ENABLE } from "../api.js";
|
2 | import { mixin } from "../mixin.js";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export const IEnableMixin = mixin({
|
11 | _enabled: true,
|
12 | isEnabled() {
|
13 | return this._enabled;
|
14 | },
|
15 | enable() {
|
16 | $enable(this, true, EVENT_ENABLE);
|
17 | },
|
18 | disable() {
|
19 | $enable(this, false, EVENT_DISABLE);
|
20 | },
|
21 | toggle() {
|
22 | this._enabled ? this.disable() : this.enable();
|
23 | return this._enabled;
|
24 | },
|
25 | });
|
26 | const $enable = (target, state, id) => {
|
27 | target._enabled = state;
|
28 | if (target.notify) {
|
29 | target.notify({ id, target });
|
30 | }
|
31 | };
|