2016-08-11 3 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

yieldおよびyield*は、ジェネレータ機能内でのみ使用できます。ここでは:

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

通常の機能の中にyield*を使用しています。また、その関数はジェネレータ(function* watchTrackingItemsLoad)である必要があります。そうでない場合は、ジェネレータオブジェクトを返して、呼び出し元に対処させる必要があります(return takeEvery(LOAD, loadTrackingItems);)。

+0

ウー男、なんて愚かな間違い!どうもありがとうございました! –