首页 > es6新语法什么意思

es6新语法什么意思

import { handleActions } from 'redux-actions';
import { combineReducer } from 'redux';

const todos = handleActions({
    
  ['todos/get'](state) {
    return { ...state, loading: true, };
  },
    //这段什么意思 ['todos/get'](state){},es6新语法吗?
  ['todos/get/success'](state, action) {
    return { ...state, list: action.payload, loading: false, };
  },
  ['todos/get/failed'](state, action) {
    return { ...state, err: action.err, loading: false, };
  },
  ['todos/delete'](state, action) {
    const id = action.payload;
    const newList = state.list.filter(todo => todo.id !== id);
    return { ...state, list: newList, };
  },
  ['todos/create'](state, action) {
    const text = action.payload;
    const newTodo = { text, };
    return { ...state, list: [newTodo, ...state.list], };
  },
  ['todos/toggleComplete'](state, action) {
    const id = action.payload;
    const newList = state.list.map(todo => {
      if (id === todo.id) {
        return { ...todo, isComplete: !todo.isComplete };
      } else {
        return todo;
      }
    });
    return { ...state, list: newList, };
  },
  ['todos/toggleCompleteAll'](state, action) {
    const isComplete = action.payload;
    const newList = state.list.map(todo => ({ ...todo, isComplete }));
    return { ...state, list: newList, };
  },
}, {
  list: [],
  loading: false,
});

export default todos;

ES6的动态属性,只是这里定义的是一个方法


应该是一种定义路由的方式吧,


'todos/get': function(state) {
    return merge(state, {loading: true});
}

(state)是动态属性.

【热门文章】
【热门文章】