Model - dennisvintherjensen/OpenClassrooms-FED-Enhance-an-existing-project GitHub Wiki
Description
Handles data for the application - create, read, update, and delete operations.
Properties
storage
: Instance of the client side storage class
Constructor
Model(storage)
: Creates a new Model instance and hooks up the storage
Parameters
{object} storage
: Instance of the client side storage class
Methods
create(title, callback)
: Creates a new to-do model
Parameters
{string} [title]
: The title of the task{function} [callback]
: The callback to fire after the model is created
read(query, callback)
: Finds and returns a model in storage. If no query is given it'll simply return everything. If you pass in a string or number it'll look that up as the ID of the model to find. Lastly, you can pass it an object to match against.
Parameters
{string|number|object} query
: A query to match models against{function} [callback]
: The callback to fire after the model is found
update(id, data, callback)
: Updates a model by giving it an ID, data to update, and a callback to fire when the update is complete.
Parameters
{number} id
: The id of the model to update{object} data
: The properties to update and their new value{function} callback
: The callback to fire when the update is complete.
remove(id, callback)
: Removes a model from storage
Parameters
{number} id
: The ID of the model to remove{function} callback
: The callback to fire when the removal is complete.
removeAll(callback)
: WARNING: Will remove ALL data from storage.
Parameters
{function} callback
: The callback to fire when the storage is wiped.
getCount(callback)
: Returns a count of all todos
Parameters
{function} callback
: The callback to fire when the storage is wiped.