我已经看过这个issue,但是按照答案的建议似乎行不通。
我在私有node_module
中创建了一个传奇,需要在运行API调用之前等待调度特定的操作。当我在模块中运行完全相同的代码时,它可以正常工作;但是,当我将此代码移至node_module
时,将无法访问已调度的动作。
这是我的代码
// node_modules/fe-utils
import { FETCH_USER_SUCCESS } from 'fe-admin';
import { takeLatest } from 'redux-saga/effects';
const { BASE_SERVICE_URL } = process.env;
export function* initSaga({
url = BASE_SERVICE_URL,
context = {},
defaults = {},
}) {
yield takeLatest([FETCH_USER_SUCCESS], function* execute() {
yield put(fetchStuff({ url, context, defaults }));
});
}
// sagas/index.js
import { initSaga } from 'fe-utils';
export default function* rootSagas() {
...
yield fork(initSaga, { url: 'http://service-url.com' });
}
// create-store.js
import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import rootReducer from './reducers';
import createRootReducer from './appState';
import rootSaga from './sagas';
export default function configureStore() {
const store = createStore(
createRootReducer(rootReducer),
{},
composeEnhancers(
applyMiddleware(
...
sagaMiddleware
)
)
);
sagaMiddleware.run(rootSaga);
return store;
}
我做错什么了吗?或者,这些动作是否根本无法在node_modules中访问?
就像我说的那样,当我将这个传奇复制/粘贴到saga/index.js
文件中时,一切工作正常,但是当移入node_module(并在本地进行符号链接)时,即使我< / p>
takeEvery('*', function* execute(action) {
console.log('ACTION', action);
});
我在模块中仍然没有任何动作。