Skip to content

Commit

Permalink
NetBridge now accepts the 'header' and 'data' attribute as a function…
Browse files Browse the repository at this point in the history
… which returns an object of the header or data respectively.
  • Loading branch information
wisdom.emenike committed Oct 16, 2019
1 parent 3f2d7f8 commit 53a65fd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions net-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Description: NetBridge is used for making asynchronous network (ajax) calls on web applications.
* Author: Wisdom Emenike
* License: MIT
* Version: 1.2
* Version: 1.3
* GitHub: https://github.com/iamwizzdom/net-bridge
*/

Expand Down Expand Up @@ -152,7 +152,7 @@ NetBridge = (function() {
if (__tm !== null) clearTimeout(__tm);
__tm = setTimeout(() => {
send(request);
}, 100);
}, 500);
return;
}

Expand Down Expand Up @@ -229,7 +229,7 @@ NetBridge = (function() {
let _tm = setTimeout(() => {
if (queue.length > 0) send(shift());
clearTimeout(_tm);
}, 100);
}, 500);
};

if (isNumeric(request.timeout)) xhttp.timeout = parseInt(request.timeout);
Expand Down Expand Up @@ -265,13 +265,17 @@ NetBridge = (function() {

xhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");

if (isFunction(request.headers)) request.headers = request.headers();

if (isObject(request.headers)) {
for (let x in request.headers) {
if (request.headers.hasOwnProperty(x))
xhttp.setRequestHeader(x, request.headers[x]);
}
}

if (isFunction(request.data)) request.data = request.data();

xhttp.send((isBoolean(request.processData) &&
request.processData === false ? request.data : serialize(request.data)));

Expand All @@ -291,4 +295,4 @@ NetBridge = (function() {

return NetBridge;

}());
}());

0 comments on commit 53a65fd

Please sign in to comment.