comparison Resources/CodeGeneration/playground2.ts @ 490:6470248790db bgo-commands-codegen

ongoing codegen work
author bgo-osimis
date Mon, 18 Feb 2019 15:38:05 +0100
parents
children
comparison
equal deleted inserted replaced
489:f6b7f113cf27 490:6470248790db
1 class Greeter {
2 greeting: string;
3 constructor(message: string) {
4 this.greeting = message;
5 }
6 greet() {
7 return "Hello, " + this.greeting;
8 }
9 }
10 enum Color {
11 Red,
12 Green,
13 Blue,
14 };
15
16 function ColorToString(value: Color)
17 {
18 switch (value)
19 {
20 case Color.Red:
21 return "Red";
22 case Color.Green:
23 return "Green";
24 case Color.Blue:
25 return "Blue";
26 default:
27 throw new Error(`Unrecognized Color value(${value})`);
28 }
29 }
30
31 let color: Color = Color.Red;
32
33 document.body.textContent = "<p>---------------------</p>"
34 document.body.textContent += "<p>********************************</p>"
35
36 class TestMessage {
37 s1: string;
38 s2: Array<string>;
39 s3: Array<Array<string>>;
40 s4: Map<string, number>;
41 s5: Map<number, Array<string>>;
42 s6: Color;
43 s7: boolean;
44 }
45
46 let tm = new TestMessage();
47 tm.s2 = new Array<string>()
48 tm.s2.push("toto");
49 tm.s2.push("toto2");
50 tm.s2.push("toto3");
51 tm.s4 = new Map<string, number>();
52 tm.s4["toto"] = 42;
53 tm.s4["toto"] = 1999;
54 tm.s4["tatata"] = 1999;
55 tm.s6 = Color.Red;
56 tm.s7 = true
57
58 let txt = JSON.stringify(tm)
59 let txtElem = document.createElement('textarea');
60 txtElem.value = txt;
61
62 document.body.appendChild(txtElem);
63
64 let greeter = new Greeter("world");
65
66 let button = document.createElement('button');
67 button.textContent = "Say Hello";
68 button.onclick = function() {
69 alert(greeter.greet());
70 }
71
72 document.body.appendChild(button);