Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: `connectionStatus.isChecking` is now a property (as described in README). It was implemented as function before BREAKING CHANGE: `connectionStatus.ok` does not return false if a connection error was persisted before until `connectionStatus.ready` resolved BREAKING CHANGE: `new ConnectionStatus(options)`: `options.cache.timeout` is now `options.cacheTimeout`
- Loading branch information
Showing
8 changed files
with
122 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
module.exports = reset | ||
|
||
var Promise = require('lie') | ||
var cache = require('./utils/cache') | ||
|
||
function reset (state, o) { | ||
var options = o || {} | ||
state.timestamp = undefined | ||
state.error = undefined | ||
return state.ready | ||
|
||
if (typeof options.interval === 'number') { | ||
var intervalTimeValue = options.interval | ||
state.interval = { | ||
connected: intervalTimeValue, | ||
disconnected: intervalTimeValue | ||
.then(function () { | ||
var options = o || {} | ||
state.timestamp = undefined | ||
state.error = undefined | ||
|
||
if (typeof options.interval === 'number') { | ||
var intervalTimeValue = options.interval | ||
state.interval = { | ||
connected: intervalTimeValue, | ||
disconnected: intervalTimeValue | ||
} | ||
} | ||
} | ||
|
||
cache.set(state) | ||
if (state.request) { | ||
state.request.abort() | ||
} | ||
|
||
if (state.request) { | ||
state.request.abort() | ||
} | ||
return cache.unset(state) | ||
}) | ||
|
||
return Promise.resolve().then(function () { | ||
.then(function () { | ||
state.emitter.emit('reset') | ||
}) | ||
} |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
module.exports = stopChecking | ||
|
||
function stopChecking (state) { | ||
clearTimeout(state.checkTimeout) | ||
delete state.checkTimeout | ||
return state.ready | ||
|
||
.then(function () { | ||
clearTimeout(state.checkTimeout) | ||
delete state.checkTimeout | ||
}) | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
module.exports = { | ||
get: getCache, | ||
set: setCache | ||
set: setCache, | ||
unset: clearCache | ||
} | ||
|
||
var internals = module.exports.internals = {} | ||
internals.store = require('humble-localstorage') | ||
|
||
function setCache (state, error) { | ||
if (state.cache === false) { | ||
return | ||
return Promise.resolve() | ||
} | ||
|
||
var data = { | ||
timestamp: state.timestamp, | ||
error: state.error | ||
} | ||
var key = state.cache.prefix + state.url | ||
|
||
internals.store.setObject(key, data) | ||
return state.cache.set(data) | ||
} | ||
|
||
function getCache (state) { | ||
if (state.cache === false) { | ||
return | ||
return Promise.resolve({}) | ||
} | ||
|
||
var key = state.cache.prefix + state.url | ||
return state.cache.get() | ||
|
||
.then(function (data) { | ||
return data | ||
}) | ||
} | ||
|
||
function clearCache (state) { | ||
if (state.cache === false) { | ||
return Promise.resolve({}) | ||
} | ||
|
||
return internals.store.getObject(key) | ||
return state.cache.unset() | ||
} |
This file contains 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 characters
This file contains 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 characters