-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWatcher.ts
48 lines (37 loc) · 797 Bytes
/
Watcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Dict } from './lib/juego/util.js'
export class Watcher {
name: string;
lastChangeTime: number = 0;
constructor( name: string ) {
this.name = name;
}
checkForChanges() {}
}
export class DictWatcher extends Watcher {
keys: Array<string> = [];
dict: Dict<any>;
constructor( name: string, dict: Dict<any> ) {
super( name );
this.dict = dict;
}
checkForChanges() {
let changed = false;
let newKeys = Object.keys( this.dict );
for ( let key of newKeys ) {
if ( !this.keys.includes( key ) ) {
changed = true;
break;
}
}
for ( let key of this.keys ) {
if ( !this.keys.includes( key ) ) {
changed = true;
break;
}
}
this.keys = Object.keys( this.dict );
if ( changed ) {
this.lastChangeTime = new Date().getTime();
}
}
}