diff --git a/src/Microsoft.Blazor.Browser.JS/src/RegisteredFunction.ts b/src/Microsoft.Blazor.Browser.JS/src/RegisteredFunction.ts new file mode 100644 index 0000000000..d6a2442665 --- /dev/null +++ b/src/Microsoft.Blazor.Browser.JS/src/RegisteredFunction.ts @@ -0,0 +1,12 @@ +const registeredFunctions = {}; + +// Code in Mono 'driver.c' looks for the registered functions here +window['__blazorRegisteredFunctions'] = registeredFunctions; + +export function registerFunction(identifier: string, implementation: Function) { + if (registeredFunctions.hasOwnProperty(identifier)) { + throw new Error(`A function with the identifier '${identifier}' has already been registered.`); + } + + registeredFunctions[identifier] = implementation; +}