diff options
Diffstat (limited to 'src/example.ts')
-rw-r--r-- | src/example.ts | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/example.ts b/src/example.ts index c23a4eb..360bf8b 100644 --- a/src/example.ts +++ b/src/example.ts @@ -126,9 +126,44 @@ const chrono = })) ]) +const doubleMapChild = + withVar(true, (isEven, updateIsEven) => + withVar('', (search, updateSearch) => { + const books = [...Array(50).keys()] + + const filteredBooks = isEven.flatMap(f => search.map(s => + books.filter(b => + (f ? b % 2 === 0 : b % 2 === 1) && + (s === '' || b.toString().includes(s))))) + + return [ + checkboxComponent({ + label: 'Even?', + isChecked: isEven, + onCheck: checked => updateIsEven(_ => checked) + }), + h( + 'input', + { oninput: (event: Event) => updateSearch(_ => (event.target as HTMLInputElement).value) + , style: 'margin-left: 1rem' + } + ), + h('hr'), + isEven.map(b => + b + ? filteredBooks.map(xs => `isEven (${xs.length})`) + : filteredBooks.map(xs => `isOdd (${xs.length})`) + ), + h('hr'), + filteredBooks.map(bs => bs.map(b => h('div', b))), + h('hr') + ] + }) + ) + const view = h('main', h('h1', 'Rx'), - chrono + doubleMapChild ) mount(view) |