Skip to content

Commit

Permalink
example: add Counter component
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 27, 2023
1 parent 5f98bed commit 45119de
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { one, createStore, html } from '../dist/one'
import { TodoList } from './components'
import { TodoList, Counter } from './components'

createStore(function () {
return {
Expand All @@ -9,10 +9,11 @@ createStore(function () {

one({
name: 'app',
components: [TodoList],
components: [TodoList, Counter],
template: html`
<div>
<todo-list></todo-list>
<counter></counter>
</div>
`,
})
21 changes: 21 additions & 0 deletions example/components/counter/Counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { html } from '../../../lib/one'

const Counter = {
name: 'counter',
template: html`
<div>
<button id="dec">-</button>
<span o-text="count"></span>
<button id="inc">+</button>
</div>
`,
state: {
count: 0,
},
setup({ query }) {
query('#dec').on('click', ({ state }) => state.count--)
query('#inc').on('click', ({ state }) => state.count++)
}
}

export { Counter }
3 changes: 3 additions & 0 deletions example/components/counter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Counter } from './Counter';

export { Counter }
4 changes: 3 additions & 1 deletion example/components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Counter } from './counter'
import { TodoList } from './todo'

export {
Counter,
TodoList,
}
}

0 comments on commit 45119de

Please sign in to comment.