我正在使用波纹管babelrc设置。

{
"presets": ["es2015", "react"]
}


然后,当我使用... reducers时,出现意外的令牌错误。
你知道如何解决吗?
我预计原因是减速器设置。
如果我在babelrc上添加“ stage-1”。它可以解决。
但是我不想添加它。请告诉我,除了在babelrc上添加“ stage-1”。

谢谢!

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import thunk from 'redux-thunk';
import * as storage from './persistence/storage';
import randomToken from './utlis/random';
import getPastDays from './utlis/pastFutureDays';
import * as reducers from './reducers';
import {
  App,
  Home,
} from './components';
import style from './css/style.css';

const reducer = combineReducers({
  ...reducers,
  routing: routerReducer,
});


./reducers/application.js

import { REGISTER_TOKEN } from '../constants';

const initialState = {
  token: null,
  createdAt: null,
};

export default function access(state = initialState, action) {
  if (action.type === REGISTER_TOKEN) {
    return { token: state.token };
  }
  return state;
}


./reducers/index.js

export { default as cityForecast } from './cityForecast';
export { default as application } from './application';

最佳答案

在下一个JavaScript版本中建议使用对象传播运算符,它使您可以使用传播(...)运算符将可枚举的属性以一种更为简洁的方式从一个对象复制到另一个对象。

不幸的是,ES6扩展运算符仅适用于数组。

如果您不想为此添加babel预设,则可以改用Object.assign

因此,您可以通过以下方式组合减速器:

const reducer = combineReducers(
    Object.assign(reducers, {routing: routerReducer})
);


您可以在这里https://googlechrome.github.io/samples/object-assign-es6/找到更多信息

08-17 09:04