From ab631c5dc48a4194d0505a6048b8877b24d8a890 Mon Sep 17 00:00:00 2001 From: jonny Date: Fri, 28 May 2021 01:46:08 +0200 Subject: [PATCH] register callbacks should be done now --- front/src/Api/iframe/IframeApiContribution.ts | 6 ++++- front/src/Api/iframe/iframe-registration.ts | 27 ------------------- 2 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 front/src/Api/iframe/iframe-registration.ts diff --git a/front/src/Api/iframe/IframeApiContribution.ts b/front/src/Api/iframe/IframeApiContribution.ts index f1fb3cd5..dc261762 100644 --- a/front/src/Api/iframe/IframeApiContribution.ts +++ b/front/src/Api/iframe/IframeApiContribution.ts @@ -1,4 +1,5 @@ import type * as tg from "generic-type-guard"; +import { registeredCallbacks } from '../../iframe_api'; import type { IframeEvent, IframeEventMap, IframeResponseEventMap } from '../Events/IframeEvent'; @@ -9,7 +10,10 @@ export function sendToWorkadventure(content: IframeEvent) type GuardedType> = Guard extends tg.TypeGuard ? T : never export function apiCallback>(callbackData: IframeCallbackContribution) { - + registeredCallbacks[callbackData.type] = { + typeChecker: callbackData.typeChecker, + callback: callbackData.callback + } return callbackData } diff --git a/front/src/Api/iframe/iframe-registration.ts b/front/src/Api/iframe/iframe-registration.ts deleted file mode 100644 index 41fb7ce6..00000000 --- a/front/src/Api/iframe/iframe-registration.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { registeredCallbacks } from "../../iframe_api"; -import type { IframeResponseEventMap } from '../Events/IframeEvent'; -/*export function registerWorkadventureCommand(commnds: T): T { - const commandPrototype = Object.getPrototypeOf(commnds); - const commandClassPropertyNames = Object.getOwnPropertyNames(commandPrototype).filter(name => name !== "constructor"); - for (const key of commandClassPropertyNames) { - window.WA[key as keyof WorkAdventureApi] = commandPrototype[key] as never - } - return commnds -} -*/ - -export function registerWorkadvntureCallback(callbacks: Array<{ - type: keyof IframeResponseEventMap, - typeChecker: Function, - callback: T -}>) { - for (const callback of callbacks) { - registeredCallbacks[callback.type] = { - typeChecker: callback.typeChecker, - callback: callback.callback - } - } - return callbacks -} - -