- Learn about Events,
EventEmitter
&Listen
- Learn how to use loops with JSX
- Server :
npm run start-04
- Tests :
npm test -- -t 04
- components/stencil-todolist/stencil-todolist.tsx
- components/stencil-todoitem/stencil-todoitem.tsx
The goal is to build a todo list with two components: stencil-todolist
and stencil-todoitem
- Open
stencil-todolist
- In the render method, loop through this.list and return stencil-todoitem component with
uid
,text
andcompleted
props
At this point if you run npm run start-04
you should see the following:
<stencil-todolist>
<stencil-todoitem id="1" text="Learn about Web Components" completed></stencil-todoitem>
<stencil-todoitem id="2" text="Learn about Stencil"></stencil-todoitem>
<stencil-todoitem id="2" text="Learn about Stencil"></stencil-todoitem>
</stencil-todolist>
Your mission is to toggle the completed
state of any item on the screen by clicking the "Toggle" buttons.
- Use
@Listen('todoCompleted')
to receive thetodoCompleted
events fromstencil-todoitem
- Update
this.list
with the newcompleted
flag state. (do not mutate this.list)
- Use
@Event() todoCompleted
of typeEventEmitter
instencil-todoitem
- Implement
handleOnComplete
method to emittodoCompleted
event withthis.uid
as argument - Add an
onClick
event on the button and callthis.handleOnComplete
- Find a way to set the class 'completed' when this.completed === true