Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { getActionTypes, connectReducers } from 'redux-refine'
- const initialState = {
- list: [{item: 'test', done: false}],
- newToDo: ''
- };
- const reducers = {
- INPUT_SUBMIT: state => Object.assign(
- {},
- state,
- {
- list: [...state.list, {item: state.newToDo, done: false }],
- newToDo: ''
- }
- ),
- INPUT_CHANGED: (state, {value}) => Object.assign(
- {},
- state,
- {newToDo: value}
- ),
- LIST_ITEM_CLICK: (state, {index}) => Object.assign(
- {},
- state,
- {
- list: [
- ...state.list.slice(0, index),
- Object.assign({}, state.list[index], {done: !state.list[index].done}),
- ...state.list.slice(index+1)
- ]
- }
- ),
- DELETE_LIST_ITEM: (state, {index}) Object.assign(
- {},
- state,
- {
- list: [
- ...state.list.slice(0, index),
- ...state.list.slice(index+1)
- ]
- }
- )
- }
- const { LIST_ITEM_CLICK, DELETE_LIST_ITEM, INPUT_SUBMIT, INPUT_CHANGED } = getActionTypes(reducers)
- export function listItemClick(index){
- return {
- type: LIST_ITEM_CLICK,
- index
- }
- }
- export function deleteListItem(index) {
- return {
- type: DELETE_LIST_ITEM,
- index
- }
- }
- export function inputSubmit(){
- return {
- type: INPUT_SUBMIT
- };
- }
- export function inputChange(value){
- return {
- type: INPUT_CHANGED,
- value
- }
- }
- export default connectRedusers(initialState, reducers, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement