import { stripIndent } from "common-tags"; import { FileWriter } from "../../base"; import { IFileWriter, TFileWriterConfig } from "../../types"; import { GlobalHelpers } from "../../../helpers"; import { AppConfig } from "../../../../app-config"; class SagaWriter extends FileWriter implements IFileWriter { constructor(protected config: TFileWriterConfig) { super(config); } getFileContent() { const { strategyName } = this.config; return stripIndent` import {takeEvery, call, put} from 'redux-saga/effects'; function* ${strategyName}({ payload, }: { type: string; payload: any; //TODO: change payload's type according to the action creator's payload's shape }){ try{ const result = yield call('doApiCallHere'); yield put('dispatchAnAction'); }catch(e){ yield put('dispatchAnAction') } } function* watch${strategyName}(){ //TODO: change actionToWatch to be the string that is the action creator's type string yield takeEvery('actionToWatch', ${strategyName}); } export { ${strategyName}, watch${strategyName} } `; } execute() { try { this.write("wx"); } catch (error) { GlobalHelpers.showError(error); } } } export { SagaWriter };