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