Skip to content

Commit

Permalink
browser: expose storage
Browse files Browse the repository at this point in the history
This patch allows overriding the default `storage` mechanism.

Closes #188.
  • Loading branch information
Stephen Mathieson committed Mar 26, 2015
1 parent 0a8e4b7 commit a6e8154
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;

/**
* Use chrome.storage.local if we are in an app
*/

var storage;

if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
storage = chrome.storage.local;
else
storage = localstorage();
exports.storage = 'undefined' != typeof chrome
&& 'undefined' != typeof chrome.storage
? chrome.storage.local
: localstorage();

/**
* Colors.
Expand Down Expand Up @@ -129,9 +122,9 @@ function log() {
function save(namespaces) {
try {
if (null == namespaces) {
storage.removeItem('debug');
exports.storage.removeItem('debug');
} else {
storage.debug = namespaces;
exports.storage.debug = namespaces;
}
} catch(e) {}
}
Expand All @@ -146,7 +139,7 @@ function save(namespaces) {
function load() {
var r;
try {
r = storage.debug;
r = exports.storage.debug;
} catch(e) {}
return r;
}
Expand Down

0 comments on commit a6e8154

Please sign in to comment.