diff --git a/examples/typescript-react/js/app.tsx b/examples/typescript-react/js/app.tsx index d302d7b432..d3a2aa3bb2 100644 --- a/examples/typescript-react/js/app.tsx +++ b/examples/typescript-react/js/app.tsx @@ -27,13 +27,13 @@ class TodoApp extends React.Component { } public componentDidMount() { - var setState = this.setState; - var router = Router({ - '/': setState.bind(this, {nowShowing: ALL_TODOS}), - '/active': setState.bind(this, {nowShowing: ACTIVE_TODOS}), - '/completed': setState.bind(this, {nowShowing: COMPLETED_TODOS}) - }); - router.init('/'); + const setState = this.setState; + const router = Router({ + '/': setState.bind(this, {nowShowing: ALL_TODOS}), + '/active': setState.bind(this, {nowShowing: ACTIVE_TODOS}), + '/completed': setState.bind(this, {nowShowing: COMPLETED_TODOS}) + }); + router.init('/'); } public handleNewTodoKeyDown(event : React.KeyboardEvent) { @@ -43,18 +43,18 @@ class TodoApp extends React.Component { event.preventDefault(); - var val = (ReactDOM.findDOMNode(this.refs["newField"]) as HTMLInputElement).value.trim(); + const val = (ReactDOM.findDOMNode(this.refs["newField"]) as HTMLInputElement).value.trim(); - if (val) { + if (val) { this.props.model.addTodo(val); (ReactDOM.findDOMNode(this.refs["newField"]) as HTMLInputElement).value = ''; } } public toggleAll(event : React.FormEvent) { - var target : any = event.target; - var checked = target.checked; - this.props.model.toggleAll(checked); + const target: any = event.target; + const checked = target.checked; + this.props.model.toggleAll(checked); } public toggle(todoToToggle : ITodo) { @@ -83,47 +83,48 @@ class TodoApp extends React.Component { } public render() { - var footer; - var main; - const todos = this.props.model.todos; - - var shownTodos = todos.filter((todo) => { - switch (this.state.nowShowing) { - case ACTIVE_TODOS: - return !todo.completed; - case COMPLETED_TODOS: - return todo.completed; - default: - return true; - } - }); - - var todoItems = shownTodos.map((todo) => { - return ( - this.cancel() } - /> - ); - }); - - // Note: It's usually better to use immutable data structures since they're + const { model } = this.props; + let footer; + let main; + const todos = model.todos; + + const shownTodos = todos.filter((todo) => { + switch (this.state.nowShowing) { + case ACTIVE_TODOS: + return !todo.completed; + case COMPLETED_TODOS: + return todo.completed; + default: + return true; + } + }); + + const todoItems = shownTodos.map((todo) => { + return ( + this.cancel()} + /> + ); + }); + + // Note: It's usually better to use immutable data structures since they're // easier to reason about and React works very well with them. That's why // we use map(), filter() and reduce() everywhere instead of mutating the // array or todo items themselves. - var activeTodoCount = todos.reduce(function (accum, todo) { - return todo.completed ? accum : accum + 1; - }, 0); + const activeTodoCount = todos.reduce(function (accum, todo) { + return todo.completed ? accum : accum + 1; + }, 0); - var completedCount = todos.length - activeTodoCount; + const completedCount = todos.length - activeTodoCount; - if (activeTodoCount || completedCount) { + if (activeTodoCount || completedCount) { footer = { } } -var model = new TodoModel('react-todos'); +const model = new TodoModel('react-todos'); function render() { ReactDOM.render( diff --git a/examples/typescript-react/js/footer.tsx b/examples/typescript-react/js/footer.tsx index e8658587e1..6515dbca14 100644 --- a/examples/typescript-react/js/footer.tsx +++ b/examples/typescript-react/js/footer.tsx @@ -14,24 +14,24 @@ import { Utils } from "./utils"; class TodoFooter extends React.Component { public render() { - var activeTodoWord = Utils.pluralize(this.props.count, 'item'); - var clearButton = null; + const { completedCount, onClearCompleted, count, nowShowing } = this.props; + let activeTodoWord = Utils.pluralize(count, 'item'); + let clearButton = null; - if (this.props.completedCount > 0) { + if (completedCount > 0) { clearButton = ( ); } - const nowShowing = this.props.nowShowing; return (