我如何定义设置方法的方法?是否将其视为元类?它实际上不一定是一个类工厂,我一直在试图找出如何在给定名称数组的情况下动态设置方法。
例如:
界面:
interface FileActionsInterface {
fetchFiles: () => void,
fetchFilesDone: () => void,
fetchFilesFail: () => void,
fetchFile: () => void,
fetchFileDone: () => void,
fetchFileFail: () => void,
createFileDone: () => void,
createFileFail: () => void,
deleteFileDone: () => void,
deleteFileFail: () => void,
}
课程:
class FileActions implements FileActionsInterface {
generateActions = alt.generateActions;
constructor() {
// a function that adds these methods to "this"
this.generateActions('fetchFiles',
'fetchFilesDone',
'fetchFilesFail',
'fetchFile',
'fetchFileDone',
'fetchFileFail',
'createFileDone',
'createFileFail',
'deleteFileDone',
'deleteFileFail');
}
createFile(file: object, thingId: number, cid?: number) {
// do stuff with this.createFileDone callback
}
deleteFile(id: number, cid: number) {
//do stuff with this.deleteFileDone callback
}
}
export default alt.createActions(FileActions);
对于过时的助焊剂存储器: