Last active
February 7, 2016 02:58
-
-
Save falkolab/d7462a1cee3e93a4bf3e to your computer and use it in GitHub Desktop.
Revisions
-
falkolab revised this gist
Jan 29, 2016 . 2 changed files with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ function anyAction() { require('networkMonitor').run(function online() { // cancel monitoring for single action after success online require('networkMonitor').cancel(online); hideNetworkNotification(); // your action code here }, function() { showNetworkNotification(); }, $) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,11 +13,11 @@ function testOnline(evt) { exports.run = function(func, failure, context) { if(typeof func !== 'function') throw "Can't run not function object."; if(Ti.Network.online) { func(); } else { this.on('online', func, context); _.isFunction(failure) && failure(); } }; -
falkolab revised this gist
Jan 29, 2016 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ var initilaized = false; function testOnline(evt) { if (evt.online) { exports.trigger('online'); } } @@ -19,24 +19,24 @@ exports.run = function(func, failure, context) { } else { func(); } }; exports.cancel = function(func, context) { this.off('online', func, context); }; exports.cancelAll = function(context) { this.off('online', null, context || null); }; exports.init = function() { !initilaized && Ti.Network.addEventListener("change", testOnline); }; exports.cleanup = function() { if(initilaized) { Ti.Network.removeEventListener('change', testOnline); this.off(); initilaized = false; } }; -
falkolab revised this gist
Jan 29, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,8 @@ exports.run = function(func, failure, context) { } } exports.cancel = function(func, context) { this.off('online', func, context) } exports.cancelAll = function(context) { -
falkolab revised this gist
Jan 29, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ // Network Monitor // Author: Andrey Tkachenko <[email protected]> // Source: https://gist.github.com/falkolab/d7462a1cee3e93a4bf3e _.extend(exports, Backbone.Events); var initilaized = false; -
falkolab revised this gist
Nov 27, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ require('networkMonitor').init(); -
falkolab revised this gist
Nov 27, 2015 . 2 changed files with 11 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ var networkMonitor = require('networkMonitor'); function anyAction() { networkMonitor.run(function() { hideNetworkNotification(); ... // your action code @@ -11,5 +11,5 @@ function anyAction() { } function cleanup() { networkMonitor.cancelAll($); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ _.extend(exports, Backbone.Events); var initilaized = false; function testOnline(evt) { if (evt.online) { exports.trigger('online') } } exports.run = function(func, failure, context) { if(typeof func !== 'function') throw "Can't run not function object."; if(!Ti.Network.online) { this.on('online', func, context); @@ -16,7 +17,7 @@ exports.runAction = function(func, failure, context) { } } exports.cancel = function(func) { this.off('online', func) } @@ -25,10 +26,13 @@ exports.cancelAll = function(context) { } exports.init = function() { !initilaized && Ti.Network.addEventListener("change", testOnline); } exports.cleanup = function() { if(initilaized) { Ti.Network.removeEventListener('change', testOnline); this.off(); initilaized = false; } } -
falkolab created this gist
Nov 27, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ var networkMonitor = require('networkMonitor'); function anyAction() { networkMonitor.runAction(function() { hideNetworkNotification(); ... // your action code }, function() { showNetworkNotification(); }, $) } function cleanup() { networkMonitor.cancelActions($); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ _.extend(exports, Backbone.Events); function testOnline(evt) { if (evt.online) { exports.trigger('online') } } exports.runAction = function(func, failure, context) { if(typeof func !== 'function') throw "Can't run not function object."; if(!Ti.Network.online) { this.on('online', func, context); _.isFunction(failure) && failure(); } else { func(); } } exports.cancelAction = function(func) { this.off('online', func) } exports.cancelAll = function(context) { this.off('online', null, context || null); } exports.init = function() { Ti.Network.addEventListener("change", testOnline); } exports.cleanup = function() { Ti.Network.removeEventListener('change', testOnline); this.off() }