【问题标题】:Typescript decorators for @OnCall and @OnRequest firebase functions?@OnCall 和 @OnRequest firebase 函数的打字稿装饰器?
【发布时间】:2019-11-16 01:36:54
【问题描述】:

我正在尝试编写一些方法装饰器以在 typescript 中与 firebase 函数一起使用,但我对语法有点困惑,而且到目前为止我尝试过的方法不起作用。

我想在我的类中有方法,例如:

@OnCall('europe-west1')
@Wrapper([errorHandler, validateSomething])
doSomething(data, context) {
// doing stuff in the function
}

最终的结果是:

const doSomething = functions.region(<REGION PARAM>).https.onCall((data, context) => {

errorHandler() {

  validateSomething() {

    DECORATEDFUNCTION()
}

});

现在包装部分虽然可取,但起初并不那么重要。到目前为止,我已经尝试了各种变体:

export function OnCall(region: string, name: string, target: any): MethodDecorator {
    return target => {
        //
    };
}

【问题讨论】:

    标签: typescript typescript-decorator


    【解决方案1】:

    对于任何偶然发现这一点的人,我最终编写了一些装饰器和一个使用它们来获得预期结果的函数,我最终放弃了这个想法,因为它似乎违背了无服务器函数的目的,并且本质上只是试图模仿具有独立功能的 REST 端点。

    The github project can be found here. 还有一个使用装饰器的示例项目。

    【讨论】:

      猜你喜欢
      • 2022-09-26
      • 2018-12-06
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2019-07-29
      • 2016-05-08
      • 1970-01-01
      相关资源
      最近更新 更多