我正在尝试在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 => {
//
};
}
答案 0 :(得分:0)
对于任何对此绊脚石的人,我最终写了一些装饰器和一个消耗它们的函数以得到预期的结果,最后,我放弃了这个主意,因为它似乎再次成为无服务器功能的目的,并且本质上只是试图模仿具有独立功能的REST端点。
The github project can be found here.还有一个使用装饰器的示例项目。