events.ts
1.55 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {ArrayUtils} from "./../utils/arrays";
export abstract class EventType {
/**
* All possible types for the event
*/
types = new Array<string>();
/**
* The event type
*/
type: string;
constructor(types: Array<string>, type: string) {
this.types = types;
this.type = type;
}
equals(other: EventType) {
return ArrayUtils.arraysEqual(this.types, other.types) && this.type === other.type;
}
}
export class ArticleEventType extends EventType {
static types = ["added", "removed"];
static removed: ArticleEventType = new ArticleEventType("removed");
static added: ArticleEventType = new ArticleEventType("added");
constructor(type: string) {
super(ArticleEventType.types, type);
}
}
/**
* A model event have a type (ModelEventType), and optionally with a model element.
* Therefore, it is possible to have events related to specific model elements.
* If the model element element is not provided, then the event is a generic event
* of the given type.
*/
export class ModelEvent {
private type: EventType;
private id: number;
static event(type: EventType, model?: noosfero.RestModel): ModelEvent {
if (model) {
return new ModelEvent(type, model.id);
} else {
return new ModelEvent(type);
}
}
constructor(type: EventType, id?: number) {
this.type = type;
this.id = id;
}
equals(other: ModelEvent) {
return other.type.equals(this.type) && other.id === this.id;
}
}