-
Notifications
You must be signed in to change notification settings - Fork 3
/
Bridge.js
118 lines (106 loc) · 2.12 KB
/
Bridge.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
window.bridge = {
send: (event) => {
console.log("send: ", { event });
},
jsonParse: (json) => {
const obj = JSON.parse(json);
console.log({ obj });
},
jsonParseRaw: (args) => {
var json = args;
const obj = JSON.parse(json);
console.log({ obj });
}
};
var TestClass = function () {
};
var Vector3 = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
Vector3.prototype.addInPlaceFromFloats = function (x, y, z) {
this.x += x;
this.y += y;
this.z += z;
};
window["FuncCallbackClass"] = function () {
const callbackActions = [];
this.register = (callbackAction) => {
if (typeof callbackAction === "function") {
callbackActions.push(callbackAction);
}
};
this.trigger = (times) => {
for (var i = 0; i < times; i++) {
callbackActions.forEach(
action => action()
);
}
}
};
const literalCallbackActions = [];
window["LiteralCallback"] = {
register: (options /* { actionHandler: () => void; } */) => {
literalCallbackActions.push(options.actionHandler);
},
trigger: (times) => {
for (var i = 0; i < times; i++) {
literalCallbackActions.forEach(
action => action()
);
}
}
};
// Primitive
window["getPrimitive"] = {
result: 999,
numberResult: 999.99,
};
window["setPrimitive"] = {
setInt: 999,
setString: "string",
setBool: true,
setNumber: 999.99,
};
window["getArray"] = {
result: ["string1", "string2"],
};
// Class
window["getObject"] = {
obj: {
X: "hello",
}
};
window["getArrayClass"] = {
obj: [{
X: "hello",
}, {
X: "world",
}]
};
window["funcClass"] = {
func: () => ({
X: "X",
Y: "Y",
Z: "Z",
}),
};
window["funcArray"] = {
func: () => [
"X1",
"Y1",
"Z1",
],
};
window["funcArrayClass"] = {
func: () => [{
X: "X1",
Y: "Y1",
Z: "Z1",
}, {
X: "X2",
Y: "Y2",
Z: "Z2",
}],
};