如何解决意外的令牌错误?

时间:2017-04-24 13:19:19

标签: javascript reactjs

我正在使用bellow babelrc设置。

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

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

谢谢!

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,
});

./减速器/ 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;
}

./减速器/ index.js

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

1 个答案:

答案 0 :(得分:1)

对象扩展运算符建议用于下一版本的JavaScript,它允许您使用spread(...)运算符以更简洁的方式将可枚举属性从一个对象复制到另一个对象。

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

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

所以你可以用以下方式组合你的减速器:

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

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