forked from CommanderXL/xRoute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
80 lines (65 loc) · 1.74 KB
/
demo.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
class Node {
constructor(parent = null) {
this._parent = parent;
this._children = new Set();
if (this.isRoot) {
Node.addRoot(this);
}
}
get isRoot() {
return !this._parent;
}
createChild() {
const node = new Node(this);
this._children.add(node);
return node;
}
removeFromParent() {
this._parent = null;
this._parent._children.delete(this);
}
get size() {
let size = 0;
for (const node of this._children) {
size += node.size;
}
size = size ? size + 1 : 1;
return size;
}
static addRoot(root) {
Node.roots = !Node.roots ? [root] : Node.roots.concat([root]);
}
static get size() {
return Node.roots
.map(root => root.size)
.reduce((a, b) => a + b);
}
}
(function (window) {
// 连接DidiJSBridge
var connectDidiJSBridge = function (callback) {
if (window.DidiJSBridge) {
callback(DidiJSBridge);
} else {
document.addEventListener('DidiJSBridgeReady', function () {
callback(DidiJSBridge);
}, false);
}
};
var btn = document.querySelector('button');
btn.addEventListener('click', function () {
var obj = {
"phone": 13000000000,
"uid": 873,
"token": "felldoo_pofelr",
"districtInfo": {
"cityName": "\u5e38\u5dde\u5e02",
"no": "0519",
"cityId": "45"
}
};
connectDidiJSBridge(function (bridge) {
bridge.callHandler('register_success', JSON.stringify(obj));
});
}, false);
})(window);