Model - RomainValy/ToDoMVC-OpenclassRoom-project GitHub Wiki
Table of Contents
Model
Creates a new Model instance and hooks up the storage.
Parameters
storageObject A reference to the client side storage class
create
Creates a new todo model
Parameters
titlestring? The title of the taskcallbackfunction? The callback to fire after the model is created
read
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
query(string | number | object)? A query to match models againstcallbackfunction? The callback to fire after the model is found
Examples
model.read(1, func); // Will find the model with an ID of 1
model.read('1'); // Same as above
//Below will find a model with foo equalling bar and hello equalling world.
model.read({ foo: 'bar', hello: 'world' });
update
Updates a model by giving it an ID, data to update, and a callback to fire when the update is complete.
Parameters
idnumber The id of the model to updatedataObject The properties to update and their new valuecallbackfunction The callback to fire when the update is complete.
remove
Removes a model from storage
Parameters
idnumber The ID of the model to removecallbackfunction The callback to fire when the removal is complete.
removeAll
WARNING: Will remove ALL data from storage.
Parameters
callbackfunction The callback to fire when the storage is wiped.
getCount
Returns a count of all todos
Parameters
callback