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:
7
docs/examples/todos-redux/src/reducers/index.js
Normal file
7
docs/examples/todos-redux/src/reducers/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import todos from './todos.js'
|
||||
import visibilityFilter from './visibilityFilter.js'
|
||||
|
||||
export default Redux.combineReducers({
|
||||
todos,
|
||||
visibilityFilter
|
||||
})
|
||||
22
docs/examples/todos-redux/src/reducers/todos.js
Normal file
22
docs/examples/todos-redux/src/reducers/todos.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const todos = (state = [], action) => {
|
||||
if(action.type == 'ADD_TODO') {
|
||||
return [
|
||||
...state,
|
||||
{
|
||||
id: action.id,
|
||||
text: action.text,
|
||||
completed: false
|
||||
}
|
||||
]
|
||||
} else if(action.type == 'TOGGLE_TODO') {
|
||||
return state.map(todo =>
|
||||
(todo.id === action.id)
|
||||
? {...todo, completed: !todo.completed}
|
||||
: todo
|
||||
)
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default todos
|
||||
11
docs/examples/todos-redux/src/reducers/visibilityFilter.js
Normal file
11
docs/examples/todos-redux/src/reducers/visibilityFilter.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { VisibilityFilters } from '../actions/index.js'
|
||||
|
||||
const visibilityFilter = (state = VisibilityFilters.SHOW_ALL, action) => {
|
||||
if(action.type == 'SET_VISIBILITY_FILTER') {
|
||||
return action.filter
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default visibilityFilter
|
||||
Reference in New Issue
Block a user