ฉันมีรหัสนี้ใน sagas.js
import { put, takeLatest } from "redux-saga/effects";
import { getArticles } from "../scripts/resources/articles";
import { GET_ARTICLES, SHOW_MATCHES } from "./constants";
function getMatches(action) {
const { searchValue } = action;
getArticles(searchValue, (matches) => {
console.log(matches)
put({ type: SHOW_MATCHES, payload: matches })
})
}
export default function* rootSaga() {
yield takeLatest(GET_MATCHES, getMatches);
}
และนี่คือฟังก์ชัน getArticles
export function getArticles(input, callBack) {
setTimeout(() => {
callBack(filterArticles(input));
}, 300);
};
การใส่ไว้ในการโทรกลับไม่ได้ส่งการดำเนินการจริง ๆ เนื่องจากฉันไม่ถึงเคสในตัวลด ฉันจะส่งการดำเนินการนี้ได้อย่างไร
function* getMatches
เพื่อให้ getMatches เป็นฟังก์ชันตัวสร้างเพื่อให้เอฟเฟกต์จาก redux-saga ทำงาน - person The Brofessor   schedule 21.06.2018{ type: SHOW_MATCHES, payload: matches }
นี่ไม่ใช่การกระทำใช่ไหม - person Matt   schedule 21.06.2018getMatches
เป็นฟังก์ชันตัวสร้างเพื่อให้ได้เอฟเฟกต์put
คุณต้องบอกผู้สร้างอย่างชัดเจนถึงเอฟเฟกต์yield
แทนที่จะเรียกput
เช่น.yield put({ type: "EXAMPLE", payload: data});
- person The Brofessor   schedule 21.06.2018yield
ด้วยput
ได้ เนื่องจากฉันกำลังส่งต่อไปยังgetArticles
ซึ่งไม่ใช่ตัวสร้าง ดังนั้นจึงเกิดข้อผิดพลาด ความคิดต่อไปของฉันคือส่งฟังก์ชันdispatch
ไปสู่เทพนิยายนี้ แต่ฉันไม่แน่ใจว่าจะต้องทำอย่างไร - person Matt   schedule 21.06.2018