aboutsummaryrefslogtreecommitdiff
path: root/src/server/Message.ts
blob: 15329249d994e09c023a76daa03de480e209cb91 (plain)
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
import { Utils } from "../Utils";
import { FIELD_ID, Field } from "../fields/Field";

export class Message<T> {
    private name: string;
    private guid: string;
    readonly ArgsCtor: new (...args: any) => T;

    get Name(): string {
        return this.name;
    }

    get Message(): string {
        return this.guid
    }

    constructor(name: string, ctor: new (...args: any) => T) {
        this.name = name;
        this.guid = Utils.GenerateDeterministicGuid(name)
        this.ArgsCtor = ctor;
    }

    GetValue() {
        return this.Name;
    }
}

class TestMessageArgs {
    hello: string = "";
}

export class SetFieldArgs {
    field: string;
    value: any;

    constructor(f: string, v: any) {
        this.field = f
        this.value = v
    }
}

export class GetFieldArgs {
    field: string;

    constructor(f: string) {
        this.field = f
    }
}

export namespace MessageStore {
    export const Foo = new Message("Foo", String);
    export const Bar = new Message("Bar", String);
    export const AddDocument = new Message("Add Document", TestMessageArgs);
    export const SetField = new Message("Set Field", SetFieldArgs)
    export const GetField = new Message("Get Field", GetFieldArgs)
}