import { mergeMap, switchMap } from 'rxjs/operators'
import { Injectable } from '@angular/core'
import { PluginService } from '@app/core/plugins/plugin.service'
+import { logger } from '@root-helpers/logger'
import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models'
import { AuthService, AuthStatus } from '../auth'
})
}
- wrapObsFun
- <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
- (fun: ObservableFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) {
+ wrapObsFun <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
+ (fun: ObservableFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) {
return from(this.pluginService.ensurePluginsAreLoaded(scope))
.pipe(
mergeMap(() => this.wrapObjectWithoutScopeLoad(params, hookParamName)),
)
}
- async wrapFun
- <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
- (fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) {
+ async wrapFun <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
+ (fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) {
await this.pluginService.ensurePluginsAreLoaded(scope)
const newParams = await this.wrapObjectWithoutScopeLoad(params, hookParamName)
}
runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
- this.pluginService.ensurePluginsAreLoaded(scope)
+ // Use setTimeout to give priority to Angular change detector
+ setTimeout(() => {
+ this.pluginService.ensurePluginsAreLoaded(scope)
.then(() => this.pluginService.runHook(hookName, undefined, params))
- .catch((err: any) => console.error('Fatal hook error.', { err }))
+ .catch((err: any) => logger.error('Fatal hook error.', err))
+ })
}
async wrapObject<T, U extends ClientFilterHookName> (result: T, scope: PluginClientScope, hookName: U) {