UNPKG

687 BJavaScriptView Raw
1import { mixin } from "../mixin.js";
2export const IWatchMixin = mixin({
3 addWatch(id, fn) {
4 this._watches = this._watches || {};
5 if (this._watches[id]) {
6 return false;
7 }
8 this._watches[id] = fn;
9 return true;
10 },
11 removeWatch(id) {
12 if (!this._watches)
13 return;
14 if (this._watches[id]) {
15 delete this._watches[id];
16 return true;
17 }
18 return false;
19 },
20 notifyWatches(oldState, newState) {
21 if (!this._watches)
22 return;
23 const w = this._watches;
24 for (let id in w) {
25 w[id](id, oldState, newState);
26 }
27 },
28});