Last active
January 13, 2022 13:07
-
-
Save jitinics/4acf7cc192e5735b1fcf262e2c5b574d to your computer and use it in GitHub Desktop.
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
@observer | |
class TodoList extends React.Component { | |
render() { | |
const store = this.props.store; | |
return ( | |
<div> | |
{ store.report } | |
<ul> | |
{ store.todos.map( | |
(todo, idx) => <TodoView todo={ todo } key={ idx } /> | |
) } | |
</ul> | |
{ store.pendingRequests > 0 ? <marquee>Loading...</marquee> : null } | |
<button onClick={ this.onNewTodo }>New Todo</button> | |
<small> (double-click a todo to edit)</small> | |
<RenderCounter /> | |
</div> | |
); | |
} | |
onNewTodo = () => { | |
this.props.store.addTodo(prompt('Enter a new todo:','coffee plz')); | |
} | |
} | |
@observer | |
class TodoView extends React.Component { | |
render() { | |
const todo = this.props.todo; | |
return ( | |
<li onDoubleClick={ this.onRename }> | |
<input | |
type='checkbox' | |
checked={ todo.completed } | |
onChange={ this.onToggleCompleted } | |
/> | |
{ todo.task } | |
{ todo.assignee | |
? <small>{ todo.assignee.name }</small> | |
: null | |
} | |
<RenderCounter /> | |
</li> | |
); | |
} | |
onToggleCompleted = () => { | |
const todo = this.props.todo; | |
todo.completed = !todo.completed; | |
} | |
onRename = () => { | |
const todo = this.props.todo; | |
todo.task = prompt('Task name', todo.task) || todo.task; | |
} | |
} | |
ReactDOM.render( | |
<TodoList store={ observableTodoStore } />, | |
document.getElementById('reactjs-app') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment