Skip to content

Commit

Permalink
example: .for() with non-object items
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 25, 2023
1 parent dd2a9b3 commit ccbbd5d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ const List = {
}
}

one({
name: 'simple-list',
state: {
items: ['Item #1', 'Item #2', 'Item #3']
},
template: html`
<div>
<ul>
<li o-text></li>
</ul>
<button id="add">Add item</button>
<button id="reset">Reset</button>
</div>
`,
setup ({ query, state }) {
const li = query('li')
const add = query('#add')
const reset = query('#reset')

add.on('click', function ({ state }) {
state.items = [...state.items, `Item #${state.items.length + 1}`]
})

reset.on('click', function ({ state }) {
state.items.splice(1, 1)
})

li.for(['items'], function ({ el, item }) {
el.style.color = 'coral'
el.style.fontWeight = 'bold'
})
}
})

one({
name: 'my-component',
components: [Test, List],
Expand Down
1 change: 1 addition & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</head>
<body>
<a href="./robots.txt" aria-label="robots.txt"></a>
<simple-list></simple-list>
<my-component msg="Hi, from a prop!"></my-component>
<test>
<p>Hejsa</p>
Expand Down

0 comments on commit ccbbd5d

Please sign in to comment.