Last active
December 20, 2016 06:25
-
-
Save Gethyl/548e3ad1580a817beaf2fc3b6b07a2bb 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
export const AddItem = (item) => ({ | |
type: "ADD_ITEM", | |
item: item | |
}) | |
export const DeleteItem = (id) => ({ | |
type: "DELETE_ITEM", | |
itemId: id | |
}) | |
export const EditIconClicked = (id) => ({ | |
type: "EDIT_ICON_CLICKED", | |
itemId: id, | |
editItem: true | |
}) | |
export const EditItem = (id,editedText) => ({ | |
type: "EDIT_ITEM", | |
itemId: id, | |
editItem: false, | |
item:editedText | |
}) | |
export const CompleteItem = (id, completedFlag) => ({ | |
type: "COMPLETED_ITEM", | |
itemId: id, | |
completed:completedFlag | |
}) |
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 update from 'immutability-helper'; | |
const initialState = { items:[]} | |
//const windowState = window.__REDUX_STATE__ | |
let id = 0; | |
const todoReducer = (state=initialState, action) => { //(state=initialState, action) => { | |
switch (action.type) { | |
case 'ADD_ITEM': | |
return { | |
...state, | |
items: state.items.concat({id:id++,text:action.item,editItem:false,completed:false}) | |
} | |
case 'DELETE_ITEM': | |
return { | |
...state, | |
items:update(state.items, {$splice: [[action.itemId, 1]]}) | |
} | |
case 'EDIT_ICON_CLICKED': | |
return { | |
...state, | |
items:update(state.items, {[action.itemId]: {editItem: {$set: true}}}) | |
} | |
case 'EDIT_ITEM': | |
return { | |
...state, | |
items:update(state.items, {[action.itemId]: {editItem: {$set: false},text: {$set: action.item}}}) | |
} | |
case 'COMPLETED_ITEM': | |
return { | |
...state, | |
items:update(state.items, {[action.itemId]: {completed: {$set: action.completed}}}) | |
} | |
default: | |
return state | |
} | |
} | |
export default todoReducer; |
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 { combineReducers } from 'redux' | |
import todoReducer from './ToDoReducers' | |
const allReducers = combineReducers({ | |
todoReducer | |
}) | |
export default allReducers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment