-
Notifications
You must be signed in to change notification settings - Fork 10.1k
/
Boot.WebAssembly.ts
36 lines (29 loc) · 1.39 KB
/
Boot.WebAssembly.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
/* eslint-disable array-element-newline */
import { Blazor } from './GlobalExports';
import { shouldAutoStart } from './BootCommon';
import { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions';
import { setWebAssemblyOptions, startWebAssembly } from './Boot.WebAssembly.Common';
import { WebAssemblyComponentDescriptor, discoverComponents } from './Services/ComponentDescriptorDiscovery';
import { DotNet } from '@microsoft/dotnet-js-interop';
import { InitialRootComponentsList } from './Services/InitialRootComponentsList';
import { JSEventRegistry } from './Services/JSEventRegistry';
import { printErr } from './Platform/Mono/MonoPlatform';
let started = false;
async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
if (started) {
throw new Error('Blazor has already started.');
}
started = true;
setWebAssemblyOptions(Promise.resolve(options || {}));
JSEventRegistry.create(Blazor);
const webAssemblyComponents = discoverComponents(document, 'webassembly') as WebAssemblyComponentDescriptor[];
const components = new InitialRootComponentsList(webAssemblyComponents);
await startWebAssembly(components);
}
Blazor.start = boot;
window['DotNet'] = DotNet;
if (shouldAutoStart()) {
boot().catch(printErr);
}