Store - dennisvintherjensen/OpenClassrooms-FED-Enhance-an-existing-project GitHub Wiki
Description
Handles the interaction with the medium in/on which data is saved
Properties
callback
: Used as fake async callback_dbName
: The name of the DB in use
Constructor
Store(name, callback)
: Creates a new client side storage object and will create an empty collection if no collection already exists.
Properties
{string} name
: The name of our DB we want to use{function} callback
: Our fake DB uses callbacks because in real life you probably would be making AJAX calls
Methods
find(query, callback)
: Finds items based on a query given as a JS object
Properties
{object} query
: The query to match against (i.e. {foo: 'bar'}){function} callback
: The callback to fire when the query completed running
findAll(callback)
: Will retrieve all data from the collection
Properties
{function} callback
: The callback to fire upon retrieving data
save(updateData, callback, id)
: 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
Properties
{object} updateData
: The data to save back into the DB{function} callback
: The callback to fire after saving{number} id
: An optional param to enter an ID of an item to update
remove(id, callback)
: Will remove an item from the Store based on its ID
Properties
{number} id
: The ID of the item you want to remove{function} callback
: The callback to fire after saving
drop(callback)
: Will drop all storage and start fresh
Properties
{function} callback
: The callback to fire after dropping the data