Created
May 29, 2019 21:03
-
-
Save iazel/be071d74bbe9b273d282171688182367 to your computer and use it in GitHub Desktop.
Todos Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { mount } from '@crui/core/dom/brower' | |
| import { Title } from './Title' | |
| mount( | |
| document.getElementById('root')! | |
| Title, | |
| {}, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { h } from '@crui/core' | |
| const input = h('input', { | |
| props: { | |
| className: 'add-todo-submit' | |
| }, | |
| events: { | |
| input: (e) => doSomething(e) | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { hp } from '@crui/core' | |
| const input = hp('input', { className: 'add-todo-submit' }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { hp } from '@crui/core' | |
| import { we } from '@crui/core/combinators/events' | |
| const input = we( | |
| hp('input', { className: 'add-todo-submit' }), | |
| { input: (e) => doSomething(e) } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { he } from '@crui/core' | |
| const input = he('input', { | |
| input: (e) => doSomething(e) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { h$ } from '@crui/reactive/elems' | |
| import { StreamBox } from '@crui/reactive/rx/box' | |
| const $box = new StreamBox('') | |
| const input = h$('input', { | |
| props: { className: 'add-todo-input' }, | |
| $bind: { value: $box } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const submit = (store: TodoStore) => | |
| h('button', { | |
| props: { className: 'add-todo-submit' }, | |
| events: { | |
| click: (e) => { | |
| e.preventDefault() | |
| store.addTodo(store.input.get()) | |
| store.input.set('') | |
| } | |
| }, | |
| children: [ | |
| text('Add') | |
| ] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const submit = h('button', { | |
| props: { className: 'add-todo-submit' }, | |
| events: { | |
| click: (e) => { | |
| e.preventDefault() | |
| // what to do? | |
| } | |
| }, | |
| children: [ | |
| text('Add') | |
| ] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type AddTodo = (todo: string) => void | |
| const submit = (todo: StreamBox<string>, addTodo: AddTodo) => | |
| h('button', { | |
| props: { className: 'add-todo-submit' }, | |
| events: { | |
| click: (e) => { | |
| e.preventDefault() | |
| addTodo(todo.get()) | |
| todo.set('') | |
| } | |
| }, | |
| children: [ | |
| text('Add') | |
| ] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ht } from '@crui/core' | |
| export const Title = ht('h1', 'TODO App') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { hc, text } from '@crui/core' | |
| const Title = hc('h1', [ | |
| text('TODO App') | |
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { StreamBox } from '@crui/reactive/rx/box' | |
| export type Todo = { | |
| text: string, | |
| } | |
| export type TodoList = Todo[] | |
| export class TodoStore { | |
| public readonly input: StreamBox<string> | |
| public readonly todos: TodoList | |
| constructor() { | |
| this.input = new StreamBox('') | |
| this.todos = [] | |
| } | |
| addTodo(todo: string): void { | |
| this.todos.push({ | |
| text: todo, | |
| }) | |
| } | |
| dispose() { | |
| this.input.destroy() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment