有人可以向我解释这个我从文档中得不到的内容: 我有这个:
import { call, put, takeEvery } from 'redux-saga/effects';
const fetchFromFirebase = () => {
return new Promise((resolve, reject) => {
firebase.database().ref('users/').once('value').then((snapshot) => {
if (snapshot) {
const teamsData = snapshot.val();
resolve(teamsData)
}
});
});
};
function* fetchTeams(action) {
console.log('here yes1');
try {
const teams = yield call(fetchFromFirebase, action.data.teams);
yield put({type: "TEAMS_FETCH_SUCCEEDED", teams: teams});
} catch (e) {
yield put({type: "USER_FETCH_FAILED", message: e.message});
}
}
function* rootSaga() {
yield takeEvery("SYNC_FIREBASE_WITH_STORE", fetchTeams);
}
export default rootSaga;
我试图通过firebase获取然后返回。我得到了我的rootSaga,调用了fetch团队然后我在检索它时做了一些事情。 但我不确定我的行为是如何被用于所有这些...
目前我无法看到console.log记录任何内容。
我的行动:
export const syncFirebaseToStore = (data) => ({
type: 'SYNC_FIREBASE_WITH_STORE',
data: data
})
export const teamsFetchSucceeded = (teams) => ({
type: 'TEAMS_FETCH_SUCCEEDED',
data: teams
});
如何才能正确调用fetchTeams
函数。
它正在调用rootSaga只是为了澄清
在我的商店里:
import rootSaga from '../sagas'
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(rootSaga)