new Model(storage)
Creates a new Model instance and hooks up the storage.
Parameters:
Name | Type | Description |
---|---|---|
storage |
object | A reference to the client side storage class |
Methods
create(titleopt, callbackopt)
Creates a new todo model
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
title |
string |
<optional> |
The content of the todo |
callback |
function |
<optional> |
The callback to fire after the model is created |
getCount()
Returns a count of all todos
read(queryopt, callbackopt)
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:
Name | Type | Attributes | Description |
---|---|---|---|
query |
string | number | object |
<optional> |
A query to match models against |
callback |
function |
<optional> |
The callback to fire after the model is found |
Example
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' });
remove(id, callback)
Removes a model from storage
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The ID of the model to remove |
callback |
function | The callback to fire when the removal is complete. |
removeAll(callback)
WARNING: Will remove ALL data from storage.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback to fire when the storage is empted. |
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:
Name | Type | Description |
---|---|---|
id |
number | The id of the model to update |
data |
object | The properties to update and their new value |
callback |
function | The callback to fire when the update is complete. |