aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/plugins/hooks.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/plugins/hooks.service.ts')
-rw-r--r--client/src/app/core/plugins/hooks.service.ts23
1 files changed, 15 insertions, 8 deletions
diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts
index 93dac1167..242741831 100644
--- a/client/src/app/core/plugins/hooks.service.ts
+++ b/client/src/app/core/plugins/hooks.service.ts
@@ -16,13 +16,10 @@ export class HooksService {
16 private pluginService: PluginService 16 private pluginService: PluginService
17 ) { } 17 ) { }
18 18
19 wrapObject<T, U extends ClientFilterHookName> (result: T, hookName: U) {
20 return this.pluginService.runHook(hookName, result)
21 }
22
23 wrapObsFun 19 wrapObsFun
24 <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName> 20 <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
25 (fun: ObservableFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { 21 (fun: ObservableFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2)
22 {
26 return from(this.pluginService.ensurePluginsAreLoaded(scope)) 23 return from(this.pluginService.ensurePluginsAreLoaded(scope))
27 .pipe( 24 .pipe(
28 mergeMap(() => this.wrapObject(params, hookParamName)), 25 mergeMap(() => this.wrapObject(params, hookParamName)),
@@ -31,10 +28,16 @@ export class HooksService {
31 ) 28 )
32 } 29 }
33 30
34 async wrapFun<U, T, V extends ClientFilterHookName> (fun: RawFunction<U, T>, params: U, hookName: V) { 31 async wrapFun
35 const result = fun(params) 32 <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
33 (fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2)
34 {
35 await this.pluginService.ensurePluginsAreLoaded(scope)
36
37 const newParams = await this.wrapObject(params, hookParamName)
38 const result = fun(newParams)
36 39
37 return this.pluginService.runHook(hookName, result, params) 40 return this.pluginService.runHook(hookResultName, result, params)
38 } 41 }
39 42
40 runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) { 43 runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
@@ -42,4 +45,8 @@ export class HooksService {
42 .then(() => this.pluginService.runHook(hookName, undefined, params)) 45 .then(() => this.pluginService.runHook(hookName, undefined, params))
43 .catch((err: any) => console.error('Fatal hook error.', { err })) 46 .catch((err: any) => console.error('Fatal hook error.', { err }))
44 } 47 }
48
49 private wrapObject<T, U extends ClientFilterHookName> (result: T, hookName: U) {
50 return this.pluginService.runHook(hookName, result)
51 }
45} 52}