veyron-browser: localStorage to localForage Part 1
The first step is to rename localStorage to store.
I intend to switch to the promises version of local forage. I'll need
to update both the src code and tests.
Change-Id: I89611e878fb8a1918c85a19a4815bcf211c3bbaf
diff --git a/package.json b/package.json
index 8ea2f29..f5f1eda 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"debug": "^1.0.4",
"guid": "^0.0.12",
"insert-css": "^0.2.0",
+ "localforage": "^1.0.2",
"mercury": "^6.0.1",
"routes": "^1.2.0",
"veyron": "git+ssh://git@github.com:veyron/veyron.js.git",
diff --git a/src/components/browse/item-details/method-form/index.js b/src/components/browse/item-details/method-form/index.js
index d8bf208..5bc0786 100644
--- a/src/components/browse/item-details/method-form/index.js
+++ b/src/components/browse/item-details/method-form/index.js
@@ -6,7 +6,7 @@
var AttributeHook = require('../../../../lib/mercury/attribute-hook');
var PropertyValueEvent =
require('../../../../lib/mercury/property-value-event');
-var store = require('../../../../lib/local-storage');
+var store = require('../../../../lib/store');
var log = require('../../../../lib/log')(
'components:browse:item-details:method-form');
var hashPropertyNames = require('../../../../lib/hashPropertyNames');
diff --git a/src/lib/local-storage.js b/src/lib/store.js
similarity index 92%
rename from src/lib/local-storage.js
rename to src/lib/store.js
index a518673..0a1c36a 100644
--- a/src/lib/local-storage.js
+++ b/src/lib/store.js
@@ -1,7 +1,7 @@
/*
- * local-storage allows key-value store for string keys and any value.
+ * The store allows key-value store for string keys and any value.
*/
-var log = require('./log')('lib:local-storage');
+var log = require('./log')('lib:store');
module.exports = {
hasValue: hasValue,
diff --git a/src/routes/browse.js b/src/routes/browse.js
index 83c8ebb..99835ed 100644
--- a/src/routes/browse.js
+++ b/src/routes/browse.js
@@ -2,7 +2,7 @@
var urlUtil = require('url');
var qsUtil = require('querystring');
var exists = require('../lib/exists');
-var store = require('../lib/local-storage');
+var store = require('../lib/store');
var smartService = require('../services/smart-service');
/*
* TODO(aghassemi) We need namespaceService.getNamespaceItem(name) method then
diff --git a/src/routes/index.js b/src/routes/index.js
index 8dbedc8..2fdb669 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -1,5 +1,5 @@
var browseRoute = require('./browse');
-var store = require('../lib/local-storage');
+var store = require('../lib/store');
module.exports = function(routes) {
routes.addRoute('/', handleIndexRoute);
diff --git a/src/services/smart-service.js b/src/services/smart-service.js
index e100bc1..fdb03e5 100644
--- a/src/services/smart-service.js
+++ b/src/services/smart-service.js
@@ -7,7 +7,7 @@
*/
var addAttributes = require('../lib/addAttributes');
-var store = require('../lib/local-storage');
+var store = require('../lib/store');
var log = require('../lib/log')('services:smart-service');
var constants = require('./smart-service-implementation');
@@ -50,7 +50,7 @@
}
/*
- * Given an id, save the learner to local-storage.
+ * Given an id, save the learner to the store.
*/
function save(id) {
if (learners[id] === undefined) {
@@ -101,7 +101,7 @@
}
/*
- * Helper function to load a new learner from local-storage.
+ * Helper function to load a new learner from the store.
*/
function load(id) {
log.debug('load', id);
diff --git a/test/unit/lib/local-storage.js b/test/unit/lib/store.js
similarity index 86%
rename from test/unit/lib/local-storage.js
rename to test/unit/lib/store.js
index 02898ac..fc1ea42 100644
--- a/test/unit/lib/local-storage.js
+++ b/test/unit/lib/store.js
@@ -1,13 +1,13 @@
var test = require('prova');
-var store = require('../../../src/lib/local-storage');
+var store = require('../../../src/lib/store');
-test('local-storage !hasValue', function(t) {
+test('store !hasValue', function(t) {
// A key not present in the store has no value.
t.notOk(store.hasValue('not in store'), 'not set => no value');
t.end();
});
-test('local-storage hasValue', function(t) {
+test('store hasValue', function(t) {
// Run hasValue between other operations and verify hasValue's output.
store.setValue('recoveringKey', 'willLoseValue');
t.ok(store.hasValue('recoveringKey'), 'set => has value');
@@ -20,13 +20,13 @@
t.end();
});
-test('local-storage get', function(t) {
+test('store get', function(t) {
// A key not present in the store has null value.
t.deepEqual(store.getValue('not in store'), null);
t.end();
});
-test('local-storage set=>get', function(t) {
+test('store set=>get', function(t) {
// Simple string is successfully recovered.
var value = 'potato soup';
store.setValue('key1', value);
@@ -50,7 +50,7 @@
t.end();
});
-test('local-storage setA=>setB=>get', function(t) {
+test('store setA=>setB=>get', function(t) {
// The last value set wins...
var key1 = 'key1';
var key2 = 'key2';
@@ -67,7 +67,7 @@
t.end();
});
-test('local-storage set=>remove=>get', function(t) {
+test('store set=>remove=>get', function(t) {
// A removed key will have no value in the store.
var key = 'will be removed';
var value = 'not null';
@@ -77,7 +77,7 @@
t.end();
});
-test('local-storage remove=>set=>get', function(t) {
+test('store remove=>set=>get', function(t) {
// A removed key is not permanent; it can be set to again.
var key = 'will be removed and set again';
var value = 'not null';
@@ -87,7 +87,7 @@
t.end();
});
-test('local-storage getKeysWithPrefix', function(t) {
+test('store getKeysWithPrefix', function(t) {
// Prepare various keys, some of which prefix the other.
store.setValue('abc', 4);
store.setValue('abcd', 'a');
diff --git a/test/unit/services/smart-service.js b/test/unit/services/smart-service.js
index c41ee58..880429d 100644
--- a/test/unit/services/smart-service.js
+++ b/test/unit/services/smart-service.js
@@ -1,6 +1,6 @@
var test = require('prova');
var addAttributes = require('../../../src/lib/addAttributes');
-var store = require('../../../src/lib/local-storage');
+var store = require('../../../src/lib/store');
var proxyquire = require('proxyquireify')(require);
// Mock of the smart service implementation file. Uses a single dumbLearner.