bigpipe-util 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -75
- package/LICENSE +19 -19
- package/README.md +3 -0
- package/bigpipe.svg +13 -13
- package/package.json +25 -25
- package/src/Primer.js +151 -134
- package/src/ServerJS.js +40 -40
- package/src/async/AsyncDOM.js +56 -56
- package/src/async/AsyncRequest.js +206 -206
- package/src/async/AsyncResponse.js +21 -21
- package/src/core/$.js +3 -3
- package/src/core/Arbiter.js +53 -53
- package/src/core/DOM.js +41 -41
- package/src/core/Dialog.js +143 -129
- package/src/core/Parent.js +38 -38
- package/src/core/ReloadPage.js +9 -9
- package/src/core/ServerRedirect.js +7 -7
- package/src/core/copyProperties.js +46 -46
- package/src/core/replaceTransportMarkers.js +27 -27
package/src/ServerJS.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import replaceTransportMarkers from "./core/replaceTransportMarkers";
|
|
2
|
-
|
|
3
|
-
function handler(dependencies, guard, context) {
|
|
4
|
-
return dependencies.map(function (args) {
|
|
5
|
-
guard.apply(context, args);
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default class ServerJS {
|
|
10
|
-
constructor() {
|
|
11
|
-
this._relativeTo = document.body;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
handle(jsMods) {
|
|
15
|
-
handler(jsMods.require || [], this._handleRequire, this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_handleRequire(modulePath, method, marker) {
|
|
19
|
-
if (method && typeof method === 'string') {
|
|
20
|
-
if (marker) {
|
|
21
|
-
replaceTransportMarkers(this._relativeTo, marker);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const factory = window.require(modulePath);
|
|
25
|
-
const context = typeof factory === 'function' ? new factory : factory;
|
|
26
|
-
|
|
27
|
-
if (!context[method]) {
|
|
28
|
-
throw new TypeError(`Module ${modulePath} has no method "${method}"`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
context[method].apply(context, marker || []);
|
|
32
|
-
} else {
|
|
33
|
-
if (marker) {
|
|
34
|
-
replaceTransportMarkers(this._relativeTo, marker);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
new (window.require(modulePath))(...(marker || []));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import replaceTransportMarkers from "./core/replaceTransportMarkers";
|
|
2
|
+
|
|
3
|
+
function handler(dependencies, guard, context) {
|
|
4
|
+
return dependencies.map(function (args) {
|
|
5
|
+
guard.apply(context, args);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default class ServerJS {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._relativeTo = document.body;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
handle(jsMods) {
|
|
15
|
+
handler(jsMods.require || [], this._handleRequire, this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_handleRequire(modulePath, method, marker) {
|
|
19
|
+
if (method && typeof method === 'string') {
|
|
20
|
+
if (marker) {
|
|
21
|
+
replaceTransportMarkers(this._relativeTo, marker);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const factory = window.require(modulePath);
|
|
25
|
+
const context = typeof factory === 'function' ? new factory : factory;
|
|
26
|
+
|
|
27
|
+
if (!context[method]) {
|
|
28
|
+
throw new TypeError(`Module ${modulePath} has no method "${method}"`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
context[method].apply(context, marker || []);
|
|
32
|
+
} else {
|
|
33
|
+
if (marker) {
|
|
34
|
+
replaceTransportMarkers(this._relativeTo, marker);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
new (window.require(modulePath))(...(marker || []));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/async/AsyncDOM.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import DOM from "../core/DOM";
|
|
2
|
-
|
|
3
|
-
export default class AsyncDOM {
|
|
4
|
-
invoke(domOps, element) {
|
|
5
|
-
for (let i = 0; i < domOps.length; ++i) {
|
|
6
|
-
let domOp = domOps[i],
|
|
7
|
-
type = domOp[0],
|
|
8
|
-
selector = domOp[1],
|
|
9
|
-
enableTarget = domOp[2],
|
|
10
|
-
content = domOp[3];
|
|
11
|
-
|
|
12
|
-
let node = enableTarget && element || null;
|
|
13
|
-
|
|
14
|
-
if (selector) {
|
|
15
|
-
node = (node || document.documentElement).querySelector(selector);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!node) {
|
|
19
|
-
console.error(`Selector '${selector}' does not match anything!`)
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
switch (type) {
|
|
24
|
-
case "eval":
|
|
25
|
-
(new Function(content)).apply(node);
|
|
26
|
-
break;
|
|
27
|
-
case "hide":
|
|
28
|
-
node.style.display = "none";
|
|
29
|
-
break;
|
|
30
|
-
case "show":
|
|
31
|
-
node.style.display = "";
|
|
32
|
-
break;
|
|
33
|
-
case "setContent":
|
|
34
|
-
DOM.setContent(node, content.__html);
|
|
35
|
-
break;
|
|
36
|
-
case "appendContent":
|
|
37
|
-
DOM.appendContent(node, content.__html);
|
|
38
|
-
break;
|
|
39
|
-
case "prependContent":
|
|
40
|
-
DOM.prependContent(node, content.__html);
|
|
41
|
-
break;
|
|
42
|
-
case "insertAfter":
|
|
43
|
-
DOM.insertAfter(node, content.__html);
|
|
44
|
-
break;
|
|
45
|
-
case "insertBefore":
|
|
46
|
-
DOM.insertBefore(node, content.__html);
|
|
47
|
-
break;
|
|
48
|
-
case "remove":
|
|
49
|
-
DOM.remove(node);
|
|
50
|
-
break;
|
|
51
|
-
case "replace":
|
|
52
|
-
DOM.replace(node, content.__html);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
1
|
+
import DOM from "../core/DOM";
|
|
2
|
+
|
|
3
|
+
export default class AsyncDOM {
|
|
4
|
+
invoke(domOps, element) {
|
|
5
|
+
for (let i = 0; i < domOps.length; ++i) {
|
|
6
|
+
let domOp = domOps[i],
|
|
7
|
+
type = domOp[0],
|
|
8
|
+
selector = domOp[1],
|
|
9
|
+
enableTarget = domOp[2],
|
|
10
|
+
content = domOp[3];
|
|
11
|
+
|
|
12
|
+
let node = enableTarget && element || null;
|
|
13
|
+
|
|
14
|
+
if (selector) {
|
|
15
|
+
node = (node || document.documentElement).querySelector(selector);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!node) {
|
|
19
|
+
console.error(`Selector '${selector}' does not match anything!`)
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
switch (type) {
|
|
24
|
+
case "eval":
|
|
25
|
+
(new Function(content)).apply(node);
|
|
26
|
+
break;
|
|
27
|
+
case "hide":
|
|
28
|
+
node.style.display = "none";
|
|
29
|
+
break;
|
|
30
|
+
case "show":
|
|
31
|
+
node.style.display = "";
|
|
32
|
+
break;
|
|
33
|
+
case "setContent":
|
|
34
|
+
DOM.setContent(node, content.__html);
|
|
35
|
+
break;
|
|
36
|
+
case "appendContent":
|
|
37
|
+
DOM.appendContent(node, content.__html);
|
|
38
|
+
break;
|
|
39
|
+
case "prependContent":
|
|
40
|
+
DOM.prependContent(node, content.__html);
|
|
41
|
+
break;
|
|
42
|
+
case "insertAfter":
|
|
43
|
+
DOM.insertAfter(node, content.__html);
|
|
44
|
+
break;
|
|
45
|
+
case "insertBefore":
|
|
46
|
+
DOM.insertBefore(node, content.__html);
|
|
47
|
+
break;
|
|
48
|
+
case "remove":
|
|
49
|
+
DOM.remove(node);
|
|
50
|
+
break;
|
|
51
|
+
case "replace":
|
|
52
|
+
DOM.replace(node, content.__html);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
import emptyFunction from "fbjs/lib/emptyFunction";
|
|
2
|
-
import AsyncResponse from "./AsyncResponse";
|
|
3
|
-
|
|
4
|
-
let requests = 0;
|
|
5
|
-
|
|
6
|
-
function serialize(obj, prefix) {
|
|
7
|
-
const str = [];
|
|
8
|
-
for(const p in obj) {
|
|
9
|
-
if (obj.hasOwnProperty(p)) {
|
|
10
|
-
const k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
|
|
11
|
-
str.push(typeof v == "object" ?
|
|
12
|
-
serialize(v, k) :
|
|
13
|
-
encodeURIComponent(k) + "=" + encodeURIComponent(v));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return str.join("&");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function validateResponseHandler(handler) {
|
|
20
|
-
const valid = !handler || typeof handler === "function";
|
|
21
|
-
|
|
22
|
-
if (!valid) {
|
|
23
|
-
console.error("AsyncRequest response handlers must be functions. Pass a function, or use bind() to build one.");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return valid;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default class AsyncRequest {
|
|
30
|
-
constructor(uri) {
|
|
31
|
-
this.method = "POST";
|
|
32
|
-
this.uri = "";
|
|
33
|
-
this.relative = null;
|
|
34
|
-
this.data = {};
|
|
35
|
-
this.headers = {};
|
|
36
|
-
this.initialHandler = emptyFunction;
|
|
37
|
-
this.handler = null;
|
|
38
|
-
this.finallyHandler = emptyFunction;
|
|
39
|
-
this.errorHandler = emptyFunction;
|
|
40
|
-
|
|
41
|
-
if (uri !== undefined) {
|
|
42
|
-
this.setURI(uri);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
setMethod(method) {
|
|
47
|
-
this.method = method.toString().toUpperCase();
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getMethod() {
|
|
52
|
-
return this.method;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
setRelative(relative) {
|
|
56
|
-
this.relative = relative;
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getRelative() {
|
|
61
|
-
return this.relative;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setData(obj) {
|
|
65
|
-
this.data = obj;
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getData() {
|
|
70
|
-
return this.data;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setRequestHeader(name, value) {
|
|
74
|
-
this.headers[name] = value;
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
setURI(uri) {
|
|
79
|
-
this.uri = uri;
|
|
80
|
-
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
getURI() {
|
|
84
|
-
return this.uri;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
setInitialHandler(fn) {
|
|
88
|
-
this.initialHandler = fn;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getInitialHandler() {
|
|
93
|
-
return this.initialHandler || emptyFunction;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
setHandler(fn) {
|
|
97
|
-
if (validateResponseHandler(fn)) {
|
|
98
|
-
this.handler = fn;
|
|
99
|
-
}
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setFinallyHandler(fn) {
|
|
104
|
-
this.finallyHandler = fn;
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getFinallyHandler() {
|
|
109
|
-
return this.finallyHandler || emptyFunction;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getHandler() {
|
|
113
|
-
return this.handler || emptyFunction;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
setErrorHandler(fn) {
|
|
117
|
-
if (validateResponseHandler(fn)) {
|
|
118
|
-
this.errorHandler = fn;
|
|
119
|
-
}
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getErrorHandler() {
|
|
124
|
-
return this.errorHandler || emptyFunction;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
abort() {
|
|
128
|
-
const transport = this.transport;
|
|
129
|
-
|
|
130
|
-
if (transport) {
|
|
131
|
-
transport.abort();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_unshieldResponseText(text) {
|
|
136
|
-
const shield = "for (;;);";
|
|
137
|
-
const shieldLength = shield.length;
|
|
138
|
-
|
|
139
|
-
if (text.length <= shieldLength) {
|
|
140
|
-
throw new Error("Response too short on async to " + this.getURI());
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return text.substring(shieldLength);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
send() {
|
|
147
|
-
const {uri, method} = this;
|
|
148
|
-
let { data } = this;
|
|
149
|
-
|
|
150
|
-
const handler = this.getHandler();
|
|
151
|
-
const errorHandler = this.getErrorHandler();
|
|
152
|
-
const initialHandler = this.getInitialHandler();
|
|
153
|
-
const getFinallyHandler = this.getFinallyHandler();
|
|
154
|
-
|
|
155
|
-
initialHandler();
|
|
156
|
-
|
|
157
|
-
const request = new XMLHttpRequest();
|
|
158
|
-
const self = this;
|
|
159
|
-
|
|
160
|
-
request.open(method, uri, true);
|
|
161
|
-
|
|
162
|
-
request.onload = function () {
|
|
163
|
-
if (this.status >= 200 && this.status < 400) {
|
|
164
|
-
let response;
|
|
165
|
-
try {
|
|
166
|
-
const safeJson = self._unshieldResponseText(this.responseText);
|
|
167
|
-
response = eval("(" + safeJson + ")");
|
|
168
|
-
} catch (e) {
|
|
169
|
-
throw new Error("Failed to handle response: " + e.message + "\n" + this.responseText);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
(new AsyncResponse).handle(response, self.relative);
|
|
173
|
-
|
|
174
|
-
handler(response);
|
|
175
|
-
} else {
|
|
176
|
-
errorHandler(this);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
getFinallyHandler(this);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
183
|
-
|
|
184
|
-
requests++;
|
|
185
|
-
|
|
186
|
-
if (data instanceof FormData) {
|
|
187
|
-
data.append('__req', requests);
|
|
188
|
-
} else {
|
|
189
|
-
data.__req = requests;
|
|
190
|
-
data = serialize(data);
|
|
191
|
-
|
|
192
|
-
if (method === "POST") {
|
|
193
|
-
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
Object.keys(this.headers).forEach((name) => {
|
|
198
|
-
request.setRequestHeader(name, this.headers[name]);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
request.onerror = errorHandler;
|
|
202
|
-
request.send(data);
|
|
203
|
-
|
|
204
|
-
return request;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
1
|
+
import emptyFunction from "fbjs/lib/emptyFunction";
|
|
2
|
+
import AsyncResponse from "./AsyncResponse";
|
|
3
|
+
|
|
4
|
+
let requests = 0;
|
|
5
|
+
|
|
6
|
+
function serialize(obj, prefix) {
|
|
7
|
+
const str = [];
|
|
8
|
+
for(const p in obj) {
|
|
9
|
+
if (obj.hasOwnProperty(p)) {
|
|
10
|
+
const k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
|
|
11
|
+
str.push(typeof v == "object" ?
|
|
12
|
+
serialize(v, k) :
|
|
13
|
+
encodeURIComponent(k) + "=" + encodeURIComponent(v));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return str.join("&");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function validateResponseHandler(handler) {
|
|
20
|
+
const valid = !handler || typeof handler === "function";
|
|
21
|
+
|
|
22
|
+
if (!valid) {
|
|
23
|
+
console.error("AsyncRequest response handlers must be functions. Pass a function, or use bind() to build one.");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return valid;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default class AsyncRequest {
|
|
30
|
+
constructor(uri) {
|
|
31
|
+
this.method = "POST";
|
|
32
|
+
this.uri = "";
|
|
33
|
+
this.relative = null;
|
|
34
|
+
this.data = {};
|
|
35
|
+
this.headers = {};
|
|
36
|
+
this.initialHandler = emptyFunction;
|
|
37
|
+
this.handler = null;
|
|
38
|
+
this.finallyHandler = emptyFunction;
|
|
39
|
+
this.errorHandler = emptyFunction;
|
|
40
|
+
|
|
41
|
+
if (uri !== undefined) {
|
|
42
|
+
this.setURI(uri);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setMethod(method) {
|
|
47
|
+
this.method = method.toString().toUpperCase();
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getMethod() {
|
|
52
|
+
return this.method;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setRelative(relative) {
|
|
56
|
+
this.relative = relative;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getRelative() {
|
|
61
|
+
return this.relative;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setData(obj) {
|
|
65
|
+
this.data = obj;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getData() {
|
|
70
|
+
return this.data;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setRequestHeader(name, value) {
|
|
74
|
+
this.headers[name] = value;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setURI(uri) {
|
|
79
|
+
this.uri = uri;
|
|
80
|
+
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
getURI() {
|
|
84
|
+
return this.uri;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setInitialHandler(fn) {
|
|
88
|
+
this.initialHandler = fn;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getInitialHandler() {
|
|
93
|
+
return this.initialHandler || emptyFunction;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setHandler(fn) {
|
|
97
|
+
if (validateResponseHandler(fn)) {
|
|
98
|
+
this.handler = fn;
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setFinallyHandler(fn) {
|
|
104
|
+
this.finallyHandler = fn;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getFinallyHandler() {
|
|
109
|
+
return this.finallyHandler || emptyFunction;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getHandler() {
|
|
113
|
+
return this.handler || emptyFunction;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setErrorHandler(fn) {
|
|
117
|
+
if (validateResponseHandler(fn)) {
|
|
118
|
+
this.errorHandler = fn;
|
|
119
|
+
}
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getErrorHandler() {
|
|
124
|
+
return this.errorHandler || emptyFunction;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
abort() {
|
|
128
|
+
const transport = this.transport;
|
|
129
|
+
|
|
130
|
+
if (transport) {
|
|
131
|
+
transport.abort();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_unshieldResponseText(text) {
|
|
136
|
+
const shield = "for (;;);";
|
|
137
|
+
const shieldLength = shield.length;
|
|
138
|
+
|
|
139
|
+
if (text.length <= shieldLength) {
|
|
140
|
+
throw new Error("Response too short on async to " + this.getURI());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return text.substring(shieldLength);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
send() {
|
|
147
|
+
const {uri, method} = this;
|
|
148
|
+
let { data } = this;
|
|
149
|
+
|
|
150
|
+
const handler = this.getHandler();
|
|
151
|
+
const errorHandler = this.getErrorHandler();
|
|
152
|
+
const initialHandler = this.getInitialHandler();
|
|
153
|
+
const getFinallyHandler = this.getFinallyHandler();
|
|
154
|
+
|
|
155
|
+
initialHandler();
|
|
156
|
+
|
|
157
|
+
const request = new XMLHttpRequest();
|
|
158
|
+
const self = this;
|
|
159
|
+
|
|
160
|
+
request.open(method, uri, true);
|
|
161
|
+
|
|
162
|
+
request.onload = function () {
|
|
163
|
+
if (this.status >= 200 && this.status < 400) {
|
|
164
|
+
let response;
|
|
165
|
+
try {
|
|
166
|
+
const safeJson = self._unshieldResponseText(this.responseText);
|
|
167
|
+
response = eval("(" + safeJson + ")");
|
|
168
|
+
} catch (e) {
|
|
169
|
+
throw new Error("Failed to handle response: " + e.message + "\n" + this.responseText);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
(new AsyncResponse).handle(response, self.relative);
|
|
173
|
+
|
|
174
|
+
handler(response);
|
|
175
|
+
} else {
|
|
176
|
+
errorHandler(this);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getFinallyHandler(this);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
183
|
+
|
|
184
|
+
requests++;
|
|
185
|
+
|
|
186
|
+
if (data instanceof FormData) {
|
|
187
|
+
data.append('__req', requests);
|
|
188
|
+
} else {
|
|
189
|
+
data.__req = requests;
|
|
190
|
+
data = serialize(data);
|
|
191
|
+
|
|
192
|
+
if (method === "POST") {
|
|
193
|
+
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Object.keys(this.headers).forEach((name) => {
|
|
198
|
+
request.setRequestHeader(name, this.headers[name]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
request.onerror = errorHandler;
|
|
202
|
+
request.send(data);
|
|
203
|
+
|
|
204
|
+
return request;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import AsyncDOM from "./AsyncDOM";
|
|
2
|
-
import ServerJS from "../ServerJS";
|
|
3
|
-
|
|
4
|
-
const _AsyncDOM = new AsyncDOM;
|
|
5
|
-
const _ServerJS = new ServerJS;
|
|
6
|
-
|
|
7
|
-
export default class AsyncResponse {
|
|
8
|
-
handle(response, element) {
|
|
9
|
-
const {domops, jsmods} = response;
|
|
10
|
-
|
|
11
|
-
if (typeof response === 'object') {
|
|
12
|
-
if (domops) {
|
|
13
|
-
_AsyncDOM.invoke(domops, element);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (jsmods) {
|
|
17
|
-
_ServerJS.handle(jsmods);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
1
|
+
import AsyncDOM from "./AsyncDOM";
|
|
2
|
+
import ServerJS from "../ServerJS";
|
|
3
|
+
|
|
4
|
+
const _AsyncDOM = new AsyncDOM;
|
|
5
|
+
const _ServerJS = new ServerJS;
|
|
6
|
+
|
|
7
|
+
export default class AsyncResponse {
|
|
8
|
+
handle(response, element) {
|
|
9
|
+
const {domops, jsmods} = response;
|
|
10
|
+
|
|
11
|
+
if (typeof response === 'object') {
|
|
12
|
+
if (domops) {
|
|
13
|
+
_AsyncDOM.invoke(domops, element);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (jsmods) {
|
|
17
|
+
_ServerJS.handle(jsmods);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
package/src/core/$.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default function (elementId) {
|
|
2
|
-
return document.getElementById(elementId);
|
|
3
|
-
}
|
|
1
|
+
export default function (elementId) {
|
|
2
|
+
return document.getElementById(elementId);
|
|
3
|
+
}
|