MCPcopy
hub / github.com/wendux/fly / EngineWrapper

Function EngineWrapper

miniprogram_dist/engine-wrapper.js:250–421  ·  view source on GitHub ↗
(adapter)

Source from the content-addressed store, hash-verified

248
249//EngineWrapper can help generating a http engine quickly through a adapter
250 function EngineWrapper(adapter) {
251 var AjaxEngine = function () {
252 function AjaxEngine() {
253 _classCallCheck(this, AjaxEngine);
254
255 this.requestHeaders = {};
256 this.readyState = 0;
257 this.timeout = 0; // 0 stands for no timeout
258 this.responseURL = "";
259 this.responseHeaders = {};
260 }
261
262 _createClass(AjaxEngine, [{
263 key: "_call",
264 value: function _call(name) {
265 this[name] && this[name].apply(this, [].splice.call(arguments, 1));
266 }
267 }, {
268 key: "_changeReadyState",
269 value: function _changeReadyState(state) {
270 this.readyState = state;
271 this._call("onreadystatechange");
272 }
273 }, {
274 key: "open",
275 value: function open(method, url) {
276 this.method = method;
277 if (!url) {
278 url = location.href;
279 } else {
280 url = util.trim(url);
281 if (url.indexOf("http") !== 0) {
282 // Normalize the request url
283 if (isBrowser) {
284 var t = document.createElement("a");
285 t.href = url;
286 url = t.href;
287 }
288 }
289 }
290 this.responseURL = url;
291 this._changeReadyState(1);
292 }
293 }, {
294 key: "send",
295 value: function send(arg) {
296 var _this = this;
297
298 arg = arg || null;
299 var self = this;
300 if (adapter) {
301 var request = {
302 method: self.method,
303 url: self.responseURL,
304 headers: self.requestHeaders || {},
305 body: arg
306 };
307 util.merge(request, self._options || {});

Callers

nothing calls this directly

Calls 5

adapterFunction · 0.85
_callMethod · 0.80
_changeReadyStateMethod · 0.80
getResponseHeaderMethod · 0.80
getAndDeleteFunction · 0.70

Tested by

no test coverage detected