redux-sunk에서 redux-saga로 전화를 걸려고 시도 중입니다. im은 사가에서 새 소식을 받았습니다. 그래서 사가 및 그 아래의 2 가지 기능에서 나온 코드 예제는 무엇입니까? 나를 도울 수있는 일이 될 것입니다 경우에 큰 도움을Redux-Sunk에서 Redux-Saga로 Redux-Thunk
var LOAD_TRANSLATIONS = exports.LOAD_TRANSLATIONS = 'loadTranslation';
// redux-thunk
var loadTranslations = exports.loadTranslations = function loadTranslations(translations) {
return function (dispatch) {
_index.I18n.forceComponentsUpdate();
dispatch({
type: LOAD_TRANSLATIONS,
translations: translations
});
};
};
// saga
function* loadTranslations() {
const lang = yield take(LOAD_TRANSLATIONS);
yield fork(getLang, lang);
}
function* getLang(lang){
console.log(lang);
yield put({
type: LOAD_TRANSLATIONS,
translations: lang
});
}
// redux-thunk
var SET_LOCALE = exports.SET_LOCALE = 'setLocal';
var setLocale = exports.setLocale = function setLocale(locale) {
return function (dispatch) {
_index.I18n.forceComponentsUpdate();
dispatch({
type: SET_LOCALE,
locale: locale
});
};
};
//saga
function* setLocale() {
const locale = yield take(SET_LOCALE);
yield fork(getLocale, locale);
}
function* getLocale(locale){
console.log(locale);
_index.I18n.forceComponentsUpdate();
yield put({
type: SET_LOCALE,
locale: locale
});
}
사가 미들웨어 등록 방법을 붙여주십시오. – gbozee
모험이 ''함수 *로 setLocale() { 수율 takeEvery (SET_LOCALE, getLocale가) } '' 동작은 'getLocale' 생성 함수에 전달과 같을 것이다. 홈 페이지의 예를 살펴보십시오. https://redux-saga.github.io/redux-saga/ – gbozee