Model - RomainValy/ToDoMVC-OpenclassRoom-project GitHub Wiki
Table of Contents
Model
Creates a new Model instance and hooks up the storage.
Parameters
storage
Object A reference to the client side storage class
create
Creates a new todo model
Parameters
title
string? The title of the taskcallback
function? 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 againstcallback
function? 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
id
number The id of the model to updatedata
Object The properties to update and their new valuecallback
function The callback to fire when the update is complete.
remove
Removes a model from storage
Parameters
id
number The ID of the model to removecallback
function The callback to fire when the removal is complete.
removeAll
WARNING: Will remove ALL data from storage.
Parameters
callback
function The callback to fire when the storage is wiped.
getCount
Returns a count of all todos
Parameters
callback