Skip to content

Commit

Permalink
Webpack support and proper scoping.
Browse files Browse the repository at this point in the history
Only use webpack and reconnect, do not use root lib.
Using modules.
Only scoped offline and reconnect the rest is not wokring.
  • Loading branch information
symunona committed Mar 13, 2023
1 parent a172918 commit e6649e9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
9 changes: 5 additions & 4 deletions coffee/offline.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extendNative = (to, from) ->

Offline = {}

Offline.options = if window.Offline then window.Offline.options or {} else {}
defaultOptions =
checks:
xhr:
Expand Down Expand Up @@ -240,16 +239,18 @@ Offline.onXHR = (cb) ->

extendNative window.XDomainRequest, _XDomainRequest

init = ->
Offline.init = (options)->
Offline.options = options or {}
if Offline.getOption 'interceptRequests'
Offline.onXHR ({xhr}) ->
unless xhr.offline is false
checkXHR xhr, Offline.markUp, Offline.confirmDown

if Offline.getOption 'checkOnLoad'
Offline.check()
if Offline.reconnect
Offline.reconnect.reset()

# We call init in a setTimeout to give time for options to be set
setTimeout init, 0

window.Offline = Offline
module.exports = Offline
8 changes: 4 additions & 4 deletions coffee/reconnect.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
unless window.Offline
throw new Error "Offline Reconnect brought in without offline.js"

Offline = require('offline')

rc = Offline.reconnect = {}

Expand Down Expand Up @@ -39,7 +39,7 @@ down = ->
reset()

rc.state = 'waiting'

Offline.trigger 'reconnect:started'
retryIntv = setInterval tick, 1000

Expand All @@ -59,7 +59,7 @@ nope = ->

rc.tryNow = tryNow

reset()
Offline.reconnect.reset = reset

Offline.on 'down', down
Offline.on 'confirmed-down', nope
Expand Down
16 changes: 8 additions & 8 deletions js/offline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
var Offline, checkXHR, defaultOptions, extendNative, grab, handlers, init;
var Offline, checkXHR, defaultOptions, extendNative, grab, handlers;

extendNative = function(to, from) {
var e, key, results, val;
Expand All @@ -21,8 +21,6 @@

Offline = {};

Offline.options = window.Offline ? window.Offline.options || {} : {};

defaultOptions = {
checks: {
xhr: {
Expand Down Expand Up @@ -287,7 +285,8 @@
}
};

init = function() {
Offline.init = function(options) {
Offline.options = options || {};
if (Offline.getOption('interceptRequests')) {
Offline.onXHR(function(arg) {
var xhr;
Expand All @@ -298,12 +297,13 @@
});
}
if (Offline.getOption('checkOnLoad')) {
return Offline.check();
Offline.check();
}
if (Offline.reconnect) {
return Offline.reconnect.reset();
}
};

setTimeout(init, 0);

window.Offline = Offline;
module.exports = Offline;

}).call(this);
22 changes: 10 additions & 12 deletions offline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! offline-js 0.7.19 */
(function() {
var Offline, checkXHR, defaultOptions, extendNative, grab, handlers, init;
var Offline, checkXHR, defaultOptions, extendNative, grab, handlers;
extendNative = function(to, from) {
var key, results, val;
results = [];
Expand All @@ -10,8 +10,7 @@
_error;
}
return results;
}, Offline = {}, Offline.options = window.Offline ? window.Offline.options || {} :{},
defaultOptions = {
}, Offline = {}, defaultOptions = {
checks:{
xhr:{
url:function() {
Expand Down Expand Up @@ -132,16 +131,15 @@
var req;
return req = new _XDomainRequest(), monitorXHR(req), req;
}, extendNative(window.XDomainRequest, _XDomainRequest);
}, init = function() {
if (Offline.getOption("interceptRequests") && Offline.onXHR(function(arg) {
}, Offline.init = function(options) {
if (Offline.options = options || {}, Offline.getOption("interceptRequests") && Offline.onXHR(function(arg) {
var xhr;
if (xhr = arg.xhr, !1 !== xhr.offline) return checkXHR(xhr, Offline.markUp, Offline.confirmDown);
}), Offline.getOption("checkOnLoad")) return Offline.check();
}, setTimeout(init, 0), window.Offline = Offline;
}), Offline.getOption("checkOnLoad") && Offline.check(), Offline.reconnect) return Offline.reconnect.reset();
}, module.exports = Offline;
}).call(this), function() {
var down, next, nope, rc, reset, retryIntv, tick, tryNow, up;
if (!window.Offline) throw new Error("Offline Reconnect brought in without offline.js");
rc = Offline.reconnect = {}, retryIntv = null, reset = function() {
var Offline, down, next, nope, rc, reset, retryIntv, tick, tryNow, up;
Offline = require("offline"), rc = Offline.reconnect = {}, retryIntv = null, reset = function() {
var ref;
return null != rc.state && "inactive" !== rc.state && Offline.trigger("reconnect:stopped"),
rc.state = "inactive", rc.remaining = rc.delay = null != (ref = Offline.getOption("reconnect.initialDelay")) ? ref :3;
Expand All @@ -163,8 +161,8 @@
}, nope = function() {
if (Offline.getOption("reconnect")) return "connecting" === rc.state ? (Offline.trigger("reconnect:failure"),
rc.state = "waiting", next()) :void 0;
}, rc.tryNow = tryNow, reset(), Offline.on("down", down), Offline.on("confirmed-down", nope),
Offline.on("up", up);
}, rc.tryNow = tryNow, Offline.reconnect.reset = reset, Offline.on("down", down),
Offline.on("confirmed-down", nope), Offline.on("up", up);
}.call(this), function() {
var clear, flush, held, holdRequest, makeRequest, waitingOnConfirm;
if (!window.Offline) throw new Error("Requests module brought in without offline.js");
Expand Down
Loading

0 comments on commit e6649e9

Please sign in to comment.