Move interop-related TS code into its own directory

This commit is contained in:
Steve Sanderson 2018-01-10 12:36:37 +00:00
parent 111e83c976
commit 247015fabb
5 changed files with 21 additions and 20 deletions

View File

@ -1,5 +1,5 @@
import { platform } from './Environment'
import { registerFunction } from './RegisteredFunction';
import { registerFunction } from './Interop/RegisteredFunction';
if (typeof window !== 'undefined') {
// When the library is loaded in a browser via a <script> element, make the

View File

@ -1,5 +1,5 @@
import { invokeWithJsonMarshalling } from './RegisteredFunction';
import { attachComponentToElement, renderRenderTree } from './Rendering/Renderer';
import { invokeWithJsonMarshalling } from './InvokeWithJsonMarshalling';
import { attachComponentToElement, renderRenderTree } from '../Rendering/Renderer';
/**
* The definitive list of internal functions invokable from .NET code.

View File

@ -0,0 +1,16 @@
import { platform } from '../Environment';
import { System_String } from '../Platform/Platform';
import { getRegisteredFunction } from './RegisteredFunction';
export function invokeWithJsonMarshalling(identifier: System_String, ...argsJson: System_String[]) {
const identifierJsString = platform.toJavaScriptString(identifier);
const funcInstance = getRegisteredFunction(identifierJsString);
const args = argsJson.map(json => JSON.parse(platform.toJavaScriptString(json)));
const result = funcInstance.apply(null, args);
if (result !== null && result !== undefined) {
const resultJson = JSON.stringify(result);
return platform.toDotNetString(resultJson);
} else {
return null;
}
}

View File

@ -1,6 +1,4 @@
import { System_String } from './Platform/Platform';
import { platform } from './Environment';
import { internalRegisteredFunctions } from './InternalRegisteredFunction';
import { internalRegisteredFunctions } from './InternalRegisteredFunction';
const registeredFunctions: { [identifier: string]: Function | undefined } = {};
@ -25,16 +23,3 @@ export function getRegisteredFunction(identifier: string): Function {
throw new Error(`Could not find registered function with name '${identifier}'.`);
}
}
export function invokeWithJsonMarshalling(identifier: System_String, ...argsJson: System_String[]) {
const identifierJsString = platform.toJavaScriptString(identifier);
const funcInstance = getRegisteredFunction(identifierJsString);
const args = argsJson.map(json => JSON.parse(platform.toJavaScriptString(json)));
const result = funcInstance.apply(null, args);
if (result !== null && result !== undefined) {
const resultJson = JSON.stringify(result);
return platform.toDotNetString(resultJson);
} else {
return null;
}
}

View File

@ -1,6 +1,6 @@
import { MethodHandle, System_Object, System_String, System_Array, Pointer, Platform } from '../Platform';
import { getAssemblyNameFromUrl } from '../DotNet';
import { getRegisteredFunction } from '../../RegisteredFunction';
import { getRegisteredFunction } from '../../Interop/RegisteredFunction';
let assembly_load: (assemblyName: string) => number;
let find_class: (assemblyHandle: number, namespace: string, className: string) => number;