Skip to content

Instantly share code, notes, and snippets.

@iazel
iazel / todoList.ts
Last active July 13, 2019 14:20
Composable UI / Todo List / Filtered
import { c$filter$$ } from '@crui/reactive/setups/filter'
const TodoList = (store: TodoStore) =>
h('ul', sc2(
props({ className: 'tood-list' }),
c$filter$$(
store.getTodos(),
TodoElement,
store.getVisibilityFilter(),
)
@iazel
iazel / store.ts
Last active July 13, 2019 14:09
Composable UI / TodoStore / Visibility Filter
class TodoStore {
private readonly visibilityFilter: $Predicate$<Todo> & Destroyable
constructor() {
this.visibilityFilter = map(this.visibility, vis2pred)
}
getVisibilityFilter(): $Preidcate$<Todo> {
return this.visibilityFilter
}
@iazel
iazel / store.ts
Last active July 13, 2019 14:04
Composable UI / TodoStore / Visibility
class TodoStore {
private readonly visibility: StreamBox<Visibility>
constructor() {
this.visibility = new StreamBox(Visibility.ALL)
}
getVisibility(): RW$B<Visibility> {
return this.visibility
}
@iazel
iazel / filter.ts
Created July 13, 2019 13:49
Composable Reactive UI / Filter
import { h, ctext, onClick } from '@crui/core'
import { map, RW$B } from '@crui/reactive/rx/box'
import { $props } from '@crui/reactive/setups/props'
const Filter = (
$vis: RW$B<Visibility>,
filterVis: Visibility,
label: string
) => {
const className = map($vis, (v) => (
import { h, ht, sc2, children } from '@crui/core'
import { bindChecked } from '@crui/reactive/setups/bind'
const hcc = (tag: Tag, className: string, cs: Component[]) =>
h(tag, sc2(
props({ className }),
children(cs)
))
export const TodoElement = (todo: Todo) => (
@iazel
iazel / store.ts
Created July 11, 2019 21:57
Composable Reactive UI / TodoStore / addTodo
addTodo(todo: string): void {
this.todos.push({
text: todo,
done: new StreamBox(false)
})
}
@iazel
iazel / todosList.ts
Last active July 11, 2019 22:03
Composable Reactive UI / TodosList - Reactive
import { c$map } from '@crui/reactive/setups/map'
const TodoList = (store: TodoStore) =>
h('ul', c$map(
store.todos,
TodoElement,
))
const TodoElement = ({ text }: Todo) =>
ht('li', text)
@iazel
iazel / store.ts
Created July 11, 2019 21:44
Composable Reactive UI / TodoStore - Todos
import { StreamBox } from '@crui/reactive/rx/box';
import { RW$B, R$L, DRW$L } from '@crui/reactive/rx/box/types';
import { StreamList } from '@crui/reactive/rx/list';
export type Todo = {
text: string,
}
export type TodoList = R$L<Todo>
export class TodoStore {
private readonly input: StreamBox<string>
@iazel
iazel / addTodo.ts
Created July 11, 2019 21:39
Composable Reactive UI / AddTodo
const AddTodo = (store: TodoStore) => hc('div', [
input(store),
submit(store)
])
@iazel
iazel / input.ts
Created July 11, 2019 21:31
Composable Reactive UI / Input with Store
import { cloneRW } from '@crui/reactive/rx/box/clone'
const input = (store: TodoStore) =>
h('input', sc2(
props({ className: 'add-todo-input' }),
bindValue(cloneRW(store.getInput()))
))