Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { getActionTypes, connectReducers } from 'redux-refine'
  2.  
  3. const initialState = {
  4.   list: [{item: 'test', done: false}],
  5.   newToDo: ''
  6. };
  7.  
  8. const reducers = {
  9.  
  10.     INPUT_SUBMIT: state => Object.assign(
  11.       {},
  12.       state,
  13.       {
  14.         list: [...state.list, {item: state.newToDo, done: false }],
  15.         newToDo: ''
  16.       }
  17.     ),
  18.  
  19.     INPUT_CHANGED: (state, {value}) => Object.assign(
  20.       {},
  21.       state,
  22.       {newToDo: value}
  23.     ),
  24.  
  25.     LIST_ITEM_CLICK: (state, {index}) => Object.assign(
  26.       {},
  27.       state,
  28.       {
  29.         list: [
  30.           ...state.list.slice(0, index),
  31.           Object.assign({}, state.list[index], {done: !state.list[index].done}),
  32.           ...state.list.slice(index+1)
  33.         ]
  34.       }
  35.     ),
  36.    
  37.     DELETE_LIST_ITEM: (state, {index}) Object.assign(
  38.       {},
  39.       state,
  40.       {
  41.         list: [
  42.           ...state.list.slice(0, index),
  43.           ...state.list.slice(index+1)
  44.         ]
  45.       }
  46.     )
  47.  
  48. }
  49.  
  50. const { LIST_ITEM_CLICK, DELETE_LIST_ITEM, INPUT_SUBMIT, INPUT_CHANGED } = getActionTypes(reducers)
  51.  
  52. export function listItemClick(index){
  53.   return {
  54.     type: LIST_ITEM_CLICK,
  55.     index
  56.   }
  57. }
  58.  
  59. export function deleteListItem(index) {
  60.   return {
  61.     type: DELETE_LIST_ITEM,
  62.     index
  63.   }
  64. }
  65.  
  66. export function inputSubmit(){
  67.   return {
  68.     type: INPUT_SUBMIT
  69.   };
  70. }
  71.  
  72. export function inputChange(value){
  73.   return {
  74.     type: INPUT_CHANGED,
  75.     value
  76.   }
  77. }
  78.  
  79. export default connectRedusers(initialState, reducers, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement