Last active
April 4, 2017 10:54
-
-
Save t4t5/2c9fe644158f2c8a21d80c41f4105e24 to your computer and use it in GitHub Desktop.
todo-list-component-3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/ui/components/todo-list/component.ts | |
| import Component, { tracked } from "@glimmer/component"; | |
| export default class TodoList extends Component { | |
| @tracked newItemText = ''; | |
| @tracked items = [ | |
| { | |
| text: "Install Glimmer", | |
| isDone: false, | |
| }, | |
| { | |
| text: "Build app", | |
| isDone: false, | |
| }, | |
| { | |
| text: "Bro down", | |
| isDone: false, | |
| } | |
| ]; | |
| updateNewItemText(e) { | |
| this.newItemText = e.target.value; | |
| } | |
| addItem() { | |
| if (!this.newItemText) return false; | |
| let items = [ | |
| ...this.items, | |
| { | |
| text: this.newItemText, | |
| isDone: false, | |
| }, | |
| ]; | |
| this.items = items; | |
| this.newItemText = ''; | |
| } | |
| deleteItem(removedItem) { | |
| let items = this.items.filter(item => { | |
| return item.text !== removedItem.text; | |
| }); | |
| this.items = items; | |
| } | |
| toggleItem(toggledItem) { | |
| let items = this.items.map(item => { | |
| if (item.text === toggledItem.text) { | |
| return Object.assign(item, { | |
| isDone: !item.isDone, | |
| }); | |
| } else { | |
| return item; | |
| } | |
| }); | |
| this.items = items; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment