The local-collection API exposes localStorage powered collections courtesy of nbubna/store, with the added power of component/enumerable.
Idea: Use localStorage to store and retrieve models, making sure each model (by id) only exists once in the application.
This will allow views using the same model to always stay in sync.
It is built to contain instances of component/model.
$ component install wejendorp/local-collection
// user-collection
var LocalCollection = require('local-collection');
var model = require('model').attr('id').attr('name');
module.exports = new LocalCollection(model);
var UserCollection = require('user-collection');
// look up the key `user.me` and return a model even if it doesnt exist:
var me = UserCollection.obtain('me', {create: true});
me.name('Wejendorp');
me.store(); // Write it back to collection.
Adds the model(s) to cache or updates an already existing model with the same id.
The model is extended with a store
method, equivalent to model.save
, but only
writing to localStorage.
Returns the model with the chosen id from cache.
Removes the model from cache.
Clears the collection store
All component/enumerable methods are available for filtering and processing.
MIT