model.js - niyogakiza/Openclassroom_Project-8 GitHub Wiki

model.js

The model.js file manages the model and its functions that allow managing the CRUD

  1. Create
  2. Read
  3. Update
  4. Delete of our tasks
  • This function creates a model instance to store database.
function Model(storage) {
		this.storage = storage;
	}

Create: It creates a new item with a title and the possibility to have a callback.

Read: This function is to find a model in the storage with two possible arguments, a query(an id) and a callback. if no query is given this will find all the data of the storage.

Update & Delete: The first function allows you to update an item, the second to delete an item then the third one deletes all items, so it updates an item by providing an id the data to update and a callback when completed and saves it.

  • getCount: This function allows us to get the todos count and perform a callback function with this count