Store - RomainValy/ToDoMVC-OpenclassRoom-project GitHub Wiki
Table of Contents
Store
Creates a new client side storage object and will create an empty collection if no collection already exists.
Parameters
name
string The name of our DB we want to usecallback
function Our fake DB uses callbacks because in real life you probably would be making AJAX calls
find
Finds items based on a query given as a JS object
Parameters
query
Object The query to match against (i.e. {foo: 'bar'})callback
function The callback to fire when the query has completed running
Examples
db.find({foo: 'bar', hello: 'world'}, function (data) {
// data will return any items that have foo: bar and
// hello: world in their properties
});
findAll
Will retrieve all data from the collection
Parameters
callback
function The callback to fire upon retrieving data
save
Will save the given data to the DB. If no item exists it will create a new item, otherwise it'll simply update an existing item's properties
getRandomId
Generate an ID
Returns String a complete random number
Parameters
updateData
Object The data to save back into the DBcallback
function The callback to fire after savingid
number An optional param to enter an ID of an item to update
remove
Will remove an item from the Store based on its ID
Parameters
drop
Will drop all storage and start fresh
Parameters
callback
function The callback to fire after dropping the data
app
Export to window