Skip to content

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 ​

ts
const loader = new KernelLoader({ rootPath: "assets", language: "python3" });
loader.showLoader("Chargement de Basthon...");
const kernel = await loader.kernelStarted();

Constructors ​

Constructor ​
ts
new KernelLoader(options, loaderId?): KernelLoader;

Start loading the kernel.

Parameters ​
ParameterTypeDescription
optionsKernelLoaderOptionsThe language and the kernel's options.
loaderId?stringThe id of the loading screen's element (default: "basthon-loader").
Returns ​

KernelLoader

Accessors ​

kernel ​
Get Signature ​
ts
get kernel(): any;

The kernel, once created (undefined before).

Returns ​

any

kernelSafe ​
Get Signature ​
ts
get kernelSafe(): any;

The kernel if it is ready to run code, null otherwise.

Returns ​

any

Methods ​

browser() ​
ts
browser(): {
  name: string;
  version: string;
};

The browser's name and version, from its user agent (shown on a loading failure).

Returns ​
ts
{
  name: string;
  version: string;
}
NameTypeDefault value
namestring"IE"
versionstring-

hideLoader() ​
ts
hideLoader(): void;

Hide the loading screen (once the kernel is started: before, or after a failure, it stays).

Returns ​

void

kernelAvailable() ​
ts
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() ​
ts
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() ​
ts
pageLoad(): Promise<void>;

Wait for the page to be loaded (document.body available).

Returns ​

Promise<void>

setErrorText() ​
ts
setErrorText(text): void;

Show an error on the loading screen (instead of its text).

Parameters ​
ParameterTypeDescription
textstringThe error's text (HTML).
Returns ​

void

setLoaderText() ​
ts
setLoaderText(text): void;

Change the text of the loading screen.

Parameters ​
ParameterTypeDescription
textstringThe new text (HTML).
Returns ​

void

showLoader() ​
ts
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 ​
ParameterTypeDefault valueDescription
textstringundefinedThe text of the loading screen (HTML).
fullscreen?booleanfalseCover the whole page (otherwise a bar at the bottom of the page).
hideAfter?booleantrueHide 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 ​
ts
new UnsupportedKernelError(language): UnsupportedKernelError;
Parameters ​
ParameterTypeDescription
languagestring | undefinedThe requested language.
Returns ​

UnsupportedKernelError

Overrides ​

Error.constructor

Properties ​

PropertyModifierTypeDescription
languagepublic readonlystring | undefinedThe 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 ​

PropertyTypeDescription
languagestringThe kernel's language: "python3" (or "python"), "sql", "ocaml", "javascript" (or "js"), "xcas", "c" or "r".