Skip to content

Commit

Permalink
example: add done state
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 27, 2023
1 parent 3fce411 commit 4363306
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 24 additions & 2 deletions example/components/todo/item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@ const TodoItem = {
template: html`
<li>
<span o-text="text"></span>
<button>Remove</button>
<span id="done">Done</span>
<div>
<button id="toggle">Toggle</button>
<button id="remove">Remove</button>
</div>
</li>
`,
setup({ query, state, parent }) {
const remove = query('button')
const remove = query('#remove')
const toggle = query('#toggle')
const done = query('#done')

const {show, hide} = done.if({ initial: state.done })

function toggleDone() {
if (state.done) {
show()
} else {
hide()
}
}

remove.on('click', function () {
parent.events.delete(state.id)
})

toggle.on('click', function () {
state.done = !state.done

toggleDone()
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions example/components/todo/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const TodoList = {
name: 'todo-list',
state: {
items: [
{ id: 1, text: 'Item #1' },
{ id: 2, text: 'Item #2' },
{ id: 3, text: 'Item #3' },
{ id: 1, text: 'Item #1', done: false },
{ id: 2, text: 'Item #2', done: false },
{ id: 3, text: 'Item #3', done: false },
]
},
components: [TodoItem],
Expand Down

0 comments on commit 4363306

Please sign in to comment.