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;
阅读 5.6k
5 个回答

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

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

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

(state)是动态属性.

不是es6的新语法,是javascript对象的字面量表示。对象的key是由字符串表示。'todos/get'虽然多了一个斜杠,但仍然是一个字符串,代表对象的一个键,这样写是为了让代码语义化,更易读。

详细可看:https://github.com/WangShuXia...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题