2016-08-11 58 views
1

使用生成器时出现问题。我收到以下错误控制台:控制台中的JavaScript生成器语法错误

ERROR in ./app/redux/sagas/tracking.saga.js Module build failed: SyntaxError: C:/Workspace/teamable-frontend/app/redux/sagas/tracking.saga.js: Unexpected token (18:4)

这里是package.json

{ 
"devDependencies": { 
    "autoprefixer-loader": "^3.2.0", 
    "babel-cli": "^6.4.5", 
    "babel-core": "^6.4.5", 
    "babel-loader": "^6.2.1", 
    "babel-plugin-transform-runtime": "^6.12.0", 
    "babel-polyfill": "^6.9.1", 
    "babel-preset-es2015": "^6.3.13", 
    "babel-preset-react": "^6.3.13", 
    "babel-preset-stage-0": "^6.5.0", 
    "babel-runtime": "^6.11.6", 
    ... 
    } 
... 
} 

和装载在webpack.config

module: { 
    loaders: [{ 
     test: /.jsx?$/, 
     loader: 'babel-loader', 
     exclude: /node_modules/, 
      query: { 
      presets: ['es2015', 'react', 'stage-0'], 
      plugins: ["transform-runtime"] 
      } 
     }, 
    ... 
} 

而使用发电机功能:

import {put, call} from 'redux-saga/effects'; 
import {takeEvery} from 'redux-saga'; 

import {LOAD} from '../../constants/ActionTypes'; 
import {loadTrackingItemsSuccess, loadTrackingItemsFail} from '../actions/tracking.actions'; 
import {getTrackingItems} from '../../mocks/ListMock' 

function* loadTrackingItems() { 
    try { 
     const trackingItems = yield call(getTrackingItems); 
     yield put(loadTrackingItemsSuccess(trackingItems)); 
    } catch(ex) { 
     yield put(loadTrackingItemsFail(ex.toString())); 
    } 
} 

export function watchTrackingItemsLoad() { 
    yield* takeEvery(LOAD, loadTrackingItems); 
} 

我做错了什么?

回答

4

yieldyield*只能在发生器功能中使用。这里:

export function watchTrackingItemsLoad() { 
    yield* takeEvery(LOAD, loadTrackingItems); 
} 

你正在使用yield*里面的一个正常功能。这个函数也应该是一个生成器(function* watchTrackingItemsLoad),或者你应该返回生成器对象并让调用者处理它(return takeEvery(LOAD, loadTrackingItems);)。

+0

Ooooh男人,多么愚蠢的错误!非常感谢你! –