-
Notifications
You must be signed in to change notification settings - Fork 0
3. Reference Guide
The reference guide was automatically generated by documentation.js, using the comments in the JS files. For the documentation of documentation.js see https://github.com/documentationjs/documentation/blob/master/docs/GETTING_STARTED.md.
Sets up a brand new Todo list.
-
name
string The name of your new to do list.
Takes a model and view and acts as the controller between them
Loads and initialises the view
locationHash
-
null
string '' | 'active' | 'completed'
An event to fire on load. Will get all items and display them in the todo-list
Renders all active tasks
Renders all completed tasks
An event to fire whenever you want to add an item. Simply pass in the event object and it'll handle the DOM insertion and saving of the new item.
title
By giving it an ID it'll find the DOM element matching that ID, remove it from the DOM and also remove it from storage.
-
id
number The ID of the item to remove from the DOM and storage
Will remove all completed items from the DOM and storage.
Give it an ID of a model and a checkbox and it will update the item in storage based on the checkbox's state.
-
id
number The ID of the element to complete or uncomplete completed
-
silent
(boolean | undefined) Prevent re-filtering the todo items -
checkbox
object The checkbox to check the state of complete or not
Will toggle ALL checkboxes' on/off state and completeness of models. Just pass in the event object.
completed
Updates the pieces of the page which change depending on the remaining number of todos.
Re-filters the todo items, based on the active route.
Simply updates the filter nav's selected states
currentPage
Creates a new Model instance and hooks up the storage.
-
storage
object A reference to the client side storage class
Creates a new todo model
-
title
string? The title of the task -
callback
function? The callback to fire after the model is created
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.
-
query
(string | number | object)? A query to match models against -
callback
function? The callback to fire after the model is found
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' });
Updates a model by giving it an ID, data to update, and a callback to fire when the update is complete.
-
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.
Removes a model from storage
-
id
number The ID of the model to remove -
callback
function The callback to fire when the removal is complete.
WARNING: Will remove ALL data from storage.
-
callback
function The callback to fire when the storage is wiped.
Returns a count of all todos
callback
Creates a new client side storage object and will create an empty collection if no collection already exists.
-
name
string The name of our DB we want to use -
callback
function Our fake DB uses callbacks because in real life you probably would be making AJAX calls
Finds items based on a query given as a JS object
-
query
object The query to match against (i.e. {foo: 'bar'}) -
callback
function The callback to fire when the query has completed running
db.find({foo: 'bar', hello: 'world'}, function (data) {
// data will return any items that have foo: bar and
// hello: world in their properties
});
Will retrieve all data from the collection
-
callback
function The callback to fire upon retrieving data
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
-
updateData
object The data to save back into the DB -
callback
function The callback to fire after saving -
id
number An optional param to enter an ID of an item to update
Will remove an item from the Store based on its ID
Will drop all storage and start fresh
-
callback
function The callback to fire after dropping the data
Sets up defaults for all the Template methods such as a default template
Creates an
NOTE: In real life you should be using a templating engine such as Mustache or Handlebars, however, this is a vanilla JS example.
-
data
object The object containing keys you want to find in the template to replace.
view.show({
id: 1,
title: "Hello World",
completed: 0,
});
Returns string HTML String of an
Displays a counter of how many to dos are left to complete
-
activeTodos
number The number of active todos.
Returns string String containing the count
Updates the text within the "Clear completed" button
-
completedTodos
[type] The number of completed todos.
Returns string String containing the count
View that abstracts away the browser's DOM completely. It has two simple entry points:
- bind(eventName, handler) Takes a todo application event and registers the handler
- render(command, parameterObject) Renders the given command with the options
template