This store provides a dojo/store interface when working with LocalStorage. Check out the Dojo Object Store Tutorial or the Creating Dojo Stores Tutorial
LocalStorage only works with key/value pairs where value is a string. Dojo-local-storage in contrast works with objects. A JSON serialization of an object is stored in LocalStorage, storing strings directly is not supported.
require(["dojo-local-storage/LocalStorage"], function (LocalStorage) {
var store = new LocalStorage({
idProperty: 'id'
});
// storing an object
var id = store.add({
title: 'Elementarteilchen',
year: 2006,
id: 'abc'
});
// querying the store
var result = store.query({
year: 2006
},{
sort: [{ attribute:"year", descending: false }]
});
// updating an object
var id = store.put({
id: 'abc',
title: 'Elementarteilchen',
year: 2006
});
// getting an object
var object = store.get('abc');
// deleting an object
store.remove('abc');
});
Sometimes it can be desirable to configure a store such that it only operates on a subset of data. This feature can be helpful to use LocalStorage as a read/writeable replacement for a remote API during development. Transparently to a client, Dojo-local-storage adds a property to each object it stores and removes it upon retrieval. Name and value of this property can be passed to the constructor upon instantiation
var store = new LocalStorage({
subsetProperty: 'mySubsetProperty',
subsetName: "movies"
});
cd <path-to-dojo-local-storage>
npm install
- Point browser to
http://<localhost>/dojo-local-storage/node_modules/intern/client.html?config=tests/intern