6. Understanding Core Concepts
Activity 6.01: Making Changes to the Model
Solution:
- The page the form is in has an area to display messages. The form itself contains the title
textfield
and a description for thetextarea
field.The page loads in the model code from the previous chapter, but also a new script, which will be created shortly. The
body
tag has an in-page event handler assigned to itsonload
event, which will be included in thecreate_todos.js
file.In order to use the model's module with events, you will need to extend it by providing an event handler for each action type. Add the following code to the bottom of the
model.js
file:function modelInit() { document.addEventListener("CREATE", modelCreateHandler); } function modelCreateHandler(ev) { todos = modelStateChange(todos, "CREATE", ev.detail); document.dispatchEvent(new Event("CHANGED", {detail: {type: "added", value: ev.detail...