javascript - es6新语法什么意思
怪我咯
怪我咯 2017-04-11 10:57:24
[JavaScript讨论组]
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;
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(4)
迷茫

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

黄舟
'todos/get': function(state) {
    return merge(state, {loading: true});
}
高洛峰

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

高洛峰

(state)是动态属性.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号