-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
model.js
41 lines (33 loc) · 670 Bytes
/
model.js
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
var nextInstanceId = 1;
module.exports = class Model {
static resetNextInstanceId() {
nextInstanceId = 1;
}
constructor(params) {
this.alive = true;
this.assignId(params != null ? params.id : undefined);
}
assignId(id) {
if (this.id == null) {
this.id = id != null ? id : nextInstanceId++;
}
if (id >= nextInstanceId) {
nextInstanceId = id + 1;
}
}
destroy() {
if (!this.isAlive()) {
return;
}
this.alive = false;
if (typeof this.destroyed === "function") {
this.destroyed();
}
}
isAlive() {
return this.alive;
}
isDestroyed() {
return !this.isAlive();
}
};