mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 05:14:28 -08:00
redux example rename
This commit is contained in:
26
docs/examples/todos-redux/src/containers/AddTodo.js
Normal file
26
docs/examples/todos-redux/src/containers/AddTodo.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { addTodo } from '../actions/index.js'
|
||||
|
||||
const h = React.createElement
|
||||
|
||||
const AddTodo = ({ dispatch }) => {
|
||||
const inputref = {}
|
||||
|
||||
return (
|
||||
h('div', null,
|
||||
h('form', {
|
||||
onSubmit: e => {
|
||||
e.preventDefault()
|
||||
if (inputref.input.value.trim()) {
|
||||
dispatch(addTodo(inputref.input.value))
|
||||
Object.assign(inputref.input, {value: ''})
|
||||
}
|
||||
}
|
||||
},
|
||||
h('input', {ref: input => Object.assign(inputref, {input})}),
|
||||
h('button', {type: 'submit'}, 'Add Todo')
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export default ReactRedux.connect()(AddTodo)
|
||||
15
docs/examples/todos-redux/src/containers/FilterLink.js
Normal file
15
docs/examples/todos-redux/src/containers/FilterLink.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { setVisibilityFilter } from '../actions/index.js'
|
||||
import Link from '../components/Link.js'
|
||||
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
active: ownProps.filter === state.visibilityFilter
|
||||
})
|
||||
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
onClick: () => dispatch(setVisibilityFilter(ownProps.filter))
|
||||
})
|
||||
|
||||
export default ReactRedux.connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Link)
|
||||
28
docs/examples/todos-redux/src/containers/VisibleTodoList.js
Normal file
28
docs/examples/todos-redux/src/containers/VisibleTodoList.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { toggleTodo } from '../actions/index.js'
|
||||
import TodoList from '../components/TodoList.js'
|
||||
import { VisibilityFilters } from '../actions/index.js'
|
||||
|
||||
const getVisibleTodos = (todos, filter) => {
|
||||
if(filter == VisibilityFilters.SHOW_ALL) {
|
||||
return todos
|
||||
} else if(filter == VisibilityFilters.SHOW_COMPLETED) {
|
||||
return todos.filter(t => t.completed)
|
||||
} else if(filter == VisibilityFilters.SHOW_ACTIVE) {
|
||||
return todos.filter(t => !t.completed)
|
||||
} else {
|
||||
throw new Error('Unknown filter: ' + filter)
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
todos: getVisibleTodos(state.todos, state.visibilityFilter)
|
||||
})
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
toggleTodo: id => dispatch(toggleTodo(id))
|
||||
})
|
||||
|
||||
export default ReactRedux.connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(TodoList)
|
||||
Reference in New Issue
Block a user