2017-04-24 2 views
1

나는 벨로우 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

오 bject spread 연산자는 spread (...) 연산자를 사용하여 한 객체에서 다른 객체로 열거 가능 속성을보다 간결하게 복사 할 수있게 해주는 다음 버전의 JavaScript에서 제안되었습니다.

불행히도 ES6 스프레드 연산자는 배열에서만 작동합니다.

바벨 사전 설정을 추가하지 않으려면 대신 Object.assign을 사용할 수 있습니다.

그래서 다음과 같은 방법으로 감속기를 결합 할 수 있습니다 : 당신은 여기 https://googlechrome.github.io/samples/object-assign-es6/

+0

가 Uhmm, I는 다음과 같이 작성하려고 더 많은 정보를 찾을 수 있습니다

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

. –

+0

'const reducerData = Object.assign ({}, reducers); \t const를 감속기 = combineReducers ({ \t reducerData, \t 라우팅 : routerReducer, \t});' 그러나 나는 아직도 그것을 해결할 수 없습니다. 작성하는 방법을 실수로합니까? –

+0

아, 해결 방법을 이해할 수 있습니다. 감사! –

관련 문제