Open elemenofi opened 9 years ago
it will be great if Offline.check() will return promise
I'd be glad to implement this feature with some guidance or pointers on where to look at.
So, any updates ? Because right now we use timeout for this purpose
Offline.check();
setTimeout(function() {
if (Offline.state === 'up'){
// do smth.
}
}, 500);
Is binding to the confirmed-up
event not an option? https://github.com/HubSpot/offline#properties
In my case I think no, because this check need to be in middle of the code and I need to be totally sure in user status. So best solution is to get promise from Offline.check() and then continue checking
It seems like you could bind to both confirmed-up
and confirmed-down
, and then remove the bindings once one of the two is called. How would that be different than a promise?
I'm thinking something along the lines of:
var initialCheck = function(cb){
var upFunc = function(){
cb(true);
unbind();
}
var downFunc = function(){
cb(false);
unbind();
}
var unbind = function(){
Offline.off('confirmed-up', upFunc);
Offline.off('confirmed-down', downFunc);
}
Offline.on('confirmed-up', upFunc);
Offline.on('confirmed-down', downFunc);
Offline.check();
}
oh , this looks good, thanks.
I am using offline.js for an HTML5 offline application. It works great but I would like to now if the client has a connection before loading my application.
Offline.js defaults to true until the first ajax call returns. Does Offline.check() support async by returning a promise or accepting a callback?
I'd like to continue my JS thread only once I know if the client is connected.
Dont know if I am being clear enough, thanks for your time!