2017-04-24 41 views
1

我正在使用bellow babelrc設置。如何解決意外的令牌錯誤?

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

然後,我當我使用......減速我得到意外的標記錯誤。 你知道如何解決它嗎? 我預計原因是減速機設置。 如果我在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'; 

回答

1

鄰爲下一個JavaScript版本提出的bject擴展運算符,它允許您使用spread(...)運算符以更簡潔的方式將可枚舉的屬性從一個對象複製到另一個對象。

不幸的是,ES6擴展運算符只適用於數組。

如果您不想爲其添加babel預設,則可以使用Object.assign代替。

所以,你可以通過以下方式結合你減速器:

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

你可以找到更多的信息在這裏https://googlechrome.github.io/samples/object-assign-es6/

+0

Uhmm,我嘗試寫這樣。 –

+0

'const reducerData = Object.assign({},redurs); \t常量減速= combineReducers({ \t reducerData, \t路由:routerReducer, \t});' 但我仍然無法解決它。 我會犯錯怎麼寫? –

+0

啊,我可以理解如何解決它。謝謝! –