rootSaga.js
saga Total entry
import { fork, all } from "redux-saga/effects";
import { assemblyLineSaga } from "@/routes/Devops/AssemblyLine/saga";
export default function* rootSaga() {
yield all([...assemblyLineSaga]);
// yield sagas.map(saga => fork(saga));
}
// export default rootSaga;
Sub-saga.js under 2.assemblyLine/saga.js
module
import { call, put, fork, takeLatest, takeEvery } from "redux-saga/effects";
// import { takeLatest } from "redux-saga";
import { getList } from "./service";
import * as Actions from "./actions";
function* getAssemblyLineList() {
try {
const assemblyLineList = yield call(getList);
yield put({
type: Actions.GET_ASSEMBLYLINE_LIST,
payload: assemblyLineList
});
} catch (error) {
yield put({ type: Actions.GET_ASSEMBLYLINE_FAILED, error });
}
}
export const assemblyLineSaga = [
takeLatest(Actions.GET_ASSEMBLYLINE_LIST, getAssemblyLineList)
];
3.action.js
export const GET_ASSEMBLYLINE_LIST = "GET_ASSEMBLYLINE_LIST";
export const GET_ASSEMBLYLINE_FAILED = "GET_ASSEMBLYLINE_FAILED";
export function getAssemblyLineList(payload) {
return {
type: GET_ASSEMBLYLINE_LIST,
payload
};
}
4.reducer.js
import * as Actions from "./actions";
export const assemblyLineReducer = (state = {}, action) => {
switch (action.type) {
case Actions.GET_ASSEMBLYLINE_LIST:
return action.payload;
default:
return state;
}
};
5.view.jsx
render() {
return (
<div>
<button onClick={this.props.getAssemblyLineList}>load</button>
</div>
);
}
export default connect(
state => ({
assemblyLine: state.assemblyLine
}),
{ getAssemblyLineList }
)(AssemblyLine);
execute getAssemblyLineList, all the time when you click the button, as shown in figure
I can"t find the cause for a long time.