如何执行具有方法设置器的Typescript元类

时间:2018-12-20 20:24:51

标签: reactjs typescript flux

我如何定义设置方法的方法?是否将其视为元类?它实际上不一定是一个类工厂,我一直在试图找出如何在给定名称数组的情况下动态设置方法。

例如:

界面:

    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);

对于过时的助焊剂存储器:

0 个答案:

没有答案