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 React from 'react' | |
import { render } from 'react-dom' | |
import { createStore } from 'redux' | |
import { Provider } from 'react-redux' | |
import App from './components/App' | |
import reducer from './reducers' | |
const store = createStore(reducer) | |
render( |
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
let nextTodoId = 0 | |
export const addTodo = (text) => ({ | |
type: 'ADD_TODO', | |
id: nextTodoId++, | |
text | |
}) | |
export const setVisibilityFilter = (filter) => ({ | |
type: 'SET_VISIBILITY_FILTER', | |
filter |
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 React from 'react' | |
import Footer from './Footer' | |
import AddTodo from '../containers/AddTodo' | |
import VisibleTodoList from '../containers/VisibleTodoList' | |
const App = () => ( | |
<div> | |
<AddTodo /> | |
<VisibleTodoList /> | |
<Footer /> |
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 React, { PropTypes } from 'react' | |
const Link = ({ active, children, onClick }) => { | |
if (active) { | |
return <span>{children}</span> | |
} | |
return ( | |
<a href="#" | |
onClick={e => { |
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 React, { PropTypes } from 'react' | |
const Todo = ({ onClick, completed, text }) => ( | |
<li | |
onClick={onClick} | |
style={{ | |
textDecoration: completed ? 'line-through' : 'none' | |
}} | |
> | |
{text} |
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 React, { PropTypes } from 'react' | |
import Todo from './Todo' | |
const TodoList = ({ todos, onTodoClick }) => ( | |
<ul> | |
{todos.map(todo => | |
<Todo | |
key={todo.id} | |
{...todo} | |
onClick={() => onTodoClick(todo.id)} |
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 React from 'react' | |
import { connect } from 'react-redux' | |
import { addTodo } from '../actions' | |
let AddTodo = ({ dispatch }) => { | |
let input | |
return ( | |
<div> | |
<form onSubmit={e => { |
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 { connect } from 'react-redux' | |
import { setVisibilityFilter } from '../actions' | |
import Link from '../components/Link' | |
const mapStateToProps = (state, ownProps) => ({ | |
active: ownProps.filter === state.visibilityFilter | |
}) | |
const mapDispatchToProps = (dispatch, ownProps) => ({ | |
onClick: () => { |
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 { connect } from 'react-redux' | |
import { toggleTodo } from '../actions' | |
import TodoList from '../components/TodoList' | |
const getVisibleTodos = (todos, filter) => { | |
switch (filter) { | |
case 'SHOW_ALL': | |
return todos | |
case 'SHOW_COMPLETED': | |
return todos.filter(t => t.completed) |
OlderNewer