UNPKG

593 BJavaScriptView Raw
1import { mixin } from "../mixin.js";
2const 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) return;
13 if (this._watches[id]) {
14 delete this._watches[id];
15 return true;
16 }
17 return false;
18 },
19 notifyWatches(oldState, newState) {
20 if (!this._watches) return;
21 const w = this._watches;
22 for (let id in w) {
23 w[id](id, oldState, newState);
24 }
25 }
26});
27export {
28 IWatchMixin
29};