Move interop-related TS code into its own directory
This commit is contained in:
parent
111e83c976
commit
247015fabb
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue