register callbacks

should be done now
This commit is contained in:
jonny 2021-05-28 01:46:08 +02:00
parent 9e6fb755d9
commit ab631c5dc4
2 changed files with 5 additions and 28 deletions

View file

@ -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<keyof IframeEventMap>)
type GuardedType<Guard extends tg.TypeGuard<unknown>> = Guard extends tg.TypeGuard<infer T> ? T : never
export function apiCallback<T extends tg.TypeGuard<unknown>>(callbackData: IframeCallbackContribution<T>) {
registeredCallbacks[callbackData.type] = {
typeChecker: callbackData.typeChecker,
callback: callbackData.callback
}
return callbackData
}

View file

@ -1,27 +0,0 @@
import { registeredCallbacks } from "../../iframe_api";
import type { IframeResponseEventMap } from '../Events/IframeEvent';
/*export function registerWorkadventureCommand<T>(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<T extends Function>(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
}