kernel-loader
Load a kernel from its language (dynamic import of its package) and show Basthon's loading screen meanwhile (see KernelLoader).
Classes
KernelLoader
Load the kernel of a language: its package is imported dynamically (a separate chunk with webpack), then the kernel is created, set as window.Basthon and given by kernelAvailable. The loader can also show Basthon's loading screen (showLoader), which initializes the kernel; without it, call the kernel's init().
Example
const loader = new KernelLoader({ rootPath: "assets", language: "python3" });
loader.showLoader("Chargement de Basthon...");
const kernel = await loader.kernelStarted();Constructors
Constructor
new KernelLoader(options, loaderId?): KernelLoader;Start loading the kernel.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | KernelLoaderOptions | The language and the kernel's options. |
loaderId? | string | The id of the loading screen's element (default: "basthon-loader"). |
Returns
Accessors
kernel
Get Signature
get kernel(): any;The kernel, once created (undefined before).
Returns
any
kernelSafe
Get Signature
get kernelSafe(): any;The kernel if it is ready to run code, null otherwise.
Returns
any
Methods
browser()
browser(): {
name: string;
version: string;
};The browser's name and version, from its user agent (shown on a loading failure).
Returns
{
name: string;
version: string;
}| Name | Type | Default value |
|---|---|---|
name | string | "IE" |
version | string | - |
hideLoader()
hideLoader(): void;Hide the loading screen (once the kernel is started: before, or after a failure, it stays).
Returns
void
kernelAvailable()
kernelAvailable(): Promise<KernelBase>;Wait for the kernel to be created (not started, see kernelStarted).
Returns
Promise<KernelBase>
The kernel.
Throws
UnsupportedKernelError if the language has no kernel.
kernelStarted()
kernelStarted(): Promise<KernelBase>;Wait for the kernel to be started (ready to run code). Its initialization is run by showLoader or by its init().
Returns
Promise<KernelBase>
The kernel.
Throws
The error of the kernel's creation, initialization or start.
pageLoad()
pageLoad(): Promise<void>;Wait for the page to be loaded (document.body available).
Returns
Promise<void>
setErrorText()
setErrorText(text): void;Show an error on the loading screen (instead of its text).
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The error's text (HTML). |
Returns
void
setLoaderText()
setLoaderText(text): void;Change the text of the loading screen.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The new text (HTML). |
Returns
void
showLoader()
showLoader(
text,
fullscreen?,
hideAfter?
): Promise<void>;Initialize the kernel and show Basthon's loading screen until it is started. On a failure (unsupported language, too old browser...), the screen shows an error and stays.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
text | string | undefined | The text of the loading screen (HTML). |
fullscreen? | boolean | false | Cover the whole page (otherwise a bar at the bottom of the page). |
hideAfter? | boolean | true | Hide the screen once the kernel is started (otherwise call hideLoader). |
Returns
Promise<void>
UnsupportedKernelError
Error of KernelLoader.kernelAvailable when the requested language has no kernel.
Extends
Error
Constructors
Constructor
new UnsupportedKernelError(language): UnsupportedKernelError;Parameters
| Parameter | Type | Description |
|---|---|---|
language | string | undefined | The requested language. |
Returns
Overrides
Error.constructor
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
language | public readonly | string | undefined | The requested language. |
Interfaces
KernelLoaderOptions
Options of the kernel loader: the language of the kernel to load and the options given to its constructor (those of all the kernels).
Extends
Properties
| Property | Type | Description |
|---|---|---|
language | string | The kernel's language: "python3" (or "python"), "sql", "ocaml", "javascript" (or "js"), "xcas", "c" or "r". |