Controller - RomainValy/ToDoMVC-OpenclassRoom-project GitHub Wiki

Table of Contents

Controller

Takes a model and view and acts as the controller between them

Parameters

  • model Object The model instance
  • view Object The view instance

setView

Loads and initialises the view

Parameters

  • locationHash string '' | 'active' | 'completed'

showAll

An event to fire on load. Will get all items and display them in the todo-list

showActive

Renders all active tasks

showCompleted

Renders all completed tasks

addItem

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.

Parameters

  • title

removeItem

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.

Parameters

  • id number The ID of the item to remove from the DOM and storage

removeCompletedItems

Will remove all completed items from the DOM and storage.

toggleComplete

Give it an ID of a model and a checkbox and it will update the item in storage based on the checkbox's state.

Parameters

  • id number The ID of the element to complete or uncomplete
  • completed Object => reference to the checkbox. The checkbox to check the state of complete or not
  • silent (boolean | undefined) Prevent re-filtering the todo items

toggleAll

Will toggle ALL checkboxes' on/off state and completeness of models. Just pass in the event object.

Parameters

  • completed

_updateCount

Updates the pieces of the page which change depending on the remaining number of todos.

_filter

Re-filters the todo items, based on the active route.

Parameters

_updateFilterState

Simply updates the filter nav's selected states

Parameters

  • currentPage

_updateCount

Update the elements on the page, which change with each completed todo

activeRoute

If the last active route isn't "All", or we're switching routes, we re-create the todo item elements, calling:

_activeRoute

Store a reference to the active route, allowing us to re-filter todo items as they are marked complete or incomplete.

Examples

this.show[All|Active|Completed]();

window

app

Export to window