A pluggable and adaptive interface to store your data on both client and server sides.
Made by Olivier Wietrich.
Datastore contains your data and all the logic surrounding it such as formatters, access control, computed properties, reset, local storage and can be easily extended with plugins (see below).
Datastore is a single wrapper for your models and collections. No more overhead, everything is just simple...
You can set a store attribute, delete or format one, update or reset the store. See API for more information.
var model = new Store({ github: 'bredele' }); store.set('name', 'olivier'); store.get('name'); // => olivier //update store.set({ github: 'datastore', plugin: 'mirror' });
An Array is an Object right? That's the main idea behind Datastore which provides the same interface to store objects and arrays.
var collection = new Store([{ name: 'olivier' }]); store.get(0).name; // => olivier
Datastore is based on an Emitter and can be used to get notified when something is changing in the store...
You can listen to changes on an attribute, know when it has been added or removed.
Datastore is the perfect compagnon to build real time applications on both client and server sides.
store.on('change name', function(value) { // => olivier }); store.set('name', 'olivier');
Datastore allows you to define computed properties in a nice and clean way.
In this example, the computed property name changes everytime the properties first or last are updated.
store.compute('name', function() { return this.first + ' ' + this.last; });
Most importantly, you can easily create plugins to extend a datastore or create elegant persistence solutions.
Here's an example of Datastore plugin. Mirror allows you to synchronize in a single line a store in client side and a store in server side.
See full list of plugins.
store.use(mirror('channel')); //set attribute name in client //and server side store.set('name', 'bredele');