From 7daec15a8eaf918730858a4502e3f29251a4d9d9 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 15 Dec 2017 20:01:23 +0000 Subject: [PATCH] Add TS part of RegisteredFunction API --- .../src/RegisteredFunction.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Microsoft.Blazor.Browser.JS/src/RegisteredFunction.ts 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; +}