Last active
February 26, 2016 19:09
-
-
Save zerkalica/647bc3a695b91d46fee0 to your computer and use it in GitHub Desktop.
New Age of ui composition
This file contains 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
export default new Map([ | |
[TodoItem, TodoItemDefaultDeps], | |
[TodoHeader, TodoHeaderDefaultDeps], | |
[TodoItemList, TodoItemListDefaultDeps], | |
[TodoFooter, TodoFooterDefaultDeps], | |
[TodoMain, TodoMainDefaultDeps] | |
]) |
This file contains 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 TodoItemModel = { | |
id: string; | |
title: string; | |
} | |
export default function TodoItem( | |
item: TodoItemModel, | |
beginEditing: () => void, | |
endEditing: () => void, | |
editingItem: TodoItemModel, | |
isEditing: boolean, | |
setEditingItem: () => void | |
) { | |
return <div> | |
{isEditing | |
? <input type="text" value={editingItem.title} onChange={setEditingItem} onEnter={endEditing} /> | |
: <div onDoubleClick={beginEditing}>{item.id}: {item.title}</div> | |
} | |
</div> | |
} |
This file contains 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 {actions, model} from '../app' | |
export const TodoItemDefaultDeps = { | |
item: '@fromProps', | |
actions.beginEditing, | |
actions.endEditing, | |
model.todo.editingItem, | |
model.todo.isEditing, | |
actions.setEditingItem | |
} |
This file contains 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 ITodoItem = Widget<{item: TodoItemModel}>; | |
export default function TodoItemList( | |
items: Array<TodoItemModel>, | |
TodoItem: ITodoItem | |
) { | |
return ( | |
<ul> | |
<li> | |
{items.map(item => | |
<TodoItem item={item}/> | |
)} | |
</li> | |
</ul> | |
) | |
} |
This file contains 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 TodoItem from './TodoItem' | |
import {actions, model} from '../app' | |
export const TodoItemDefaultDeps = { | |
items: model.todo.todos, | |
TodoItem | |
} |
This file contains 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
export default function TodoMain( | |
TodoHeader: Widget<void>, | |
TodoItemList: Widget<void>, | |
TodoFooter: Widget<void> | |
) { | |
return ( | |
<div> | |
<TodoHeader/> | |
<TodoItemList/> | |
<TodoFooter/> | |
</div> | |
) | |
} |
This file contains 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 TodoHeader from './TodoHeader' | |
import TodoFooter from './TodoFooter' | |
import TodoItemList from './TodoItemList' | |
export const TodoItemDefaultDeps = { | |
TodoHeader, | |
TodoItemList, | |
TodoFooter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment