crud stor
Minimal model with crud operations.
install
$ npm install crud-stor
example
var Store = ; // api is an object with get, add, edit, delete functionsvar api = ; var store = ; // store.state is an instance of `observ`store; store; // => { isResolving: false, data: {} } // call api.<method> and set the state with the response {}storeactions;storeactions;storeactions;storeactions; // set one item to the given object, or add it if the id does not exist// emits a change eventstore; // set all items and emit a change eventstore;
API functions are any asynchronous function that takes an options arg and a node style callback.
// mock-api.jsvar nextTick = processnextTick; moduleexports = { ; } { ; } { ; } { ; };
Parse data:
var Store = ;var store = ;var xtend = ; // return a new observable with parsed datavar parsed = Store; { return ;} // listen to changes;
api
var store = Store({ id: 'idProperty' }, api)
Store
takes an object that tells what property to index by. api
is an object with get, add, edit, and delete functions. The returned store
is an object like:
state: observ actions: get: fn add: fn edit: fn delete: fn set: fn reset: fn
store.set(object data)
Set one item.
store.reset(array data)
Reset all the items.
Store.Parse(observable, function parser)
Return a new observ
that emits the return value from parser
. Parser is a
function that takes the state object emitted by observable
:
/* ... */