Class Kernel

Singleton Kernel class. The Kernel is essentially a dependency loader for ESM bundles (and their respective importmaps) or, depending on the runtime context and capabilities, UMD bundles and their transitive dependencies. By making use of the Kernel, applications based on the SGRUD client libraries may be comprised of multiple, optionally loaded Kernel.Modules.

Decorator

Singleton

Constructors

  • Singleton constructor. The first time, this constructor is called, it will persist the nodeModules path Kernel.Modules should be loaded from. Subsequent constructor calls will ignore this argument and return the Singleton instance. Through subscribing to the Subscribable returned by the well-known Symbol.observable method, the Kernel.Module loading progress can be tracked.

    Parameters

    • nodeModules: string = '/node_modules'

      Optional location to load node modules from.

    Returns Kernel

    Example

    Instantiate the Kernel and require Kernel.Modules:

    import { Kernel } from '@sgrud/core';
    import { forkJoin } from 'rxjs';

    const kernel = new Kernel('https://unpkg.com');

    forkJoin([
    kernel.require('example-module'),
    kernel.require('/static/local-module')
    ]).subscribe(console.log);

Properties

nodeModules: string = '/node_modules'

Optional location to load node modules from.

Default Value

'/node_modules'

Internal ReplaySubject tracking the loading state and therefore changes of loaded Kernel.Modules. An Observable form of this internal ReplaySubject may be retrieved by invoking the well-known Symbol.observable method and subscribing to the returned Subscribable. The internal changes ReplaySubject emits all Kernel.Module definitions loaded throughout the lifespan of this class.

imports: Map<string, string>

Internal Mapping to keep track of all via importmaps declared Kernel.Module identifiers to their corresponding paths. This map is used for housekeeping, e.g., to prevent the same Kernel.Module identifier to be defined multiple times.

loaders: Map<string, ReplaySubject<Module>>

Internal Mapping of all Kernel.Modules loaders to a ReplaySubject. This ReplaySubject tracks the loading process as such, that it emits the Kernel.Module definition once the respective Kernel.Module is fully loaded (including dependencies etc.) and then completes.

shimmed: string

Internally used string to suffix the importmap and module types of HTMLScriptElements with, if applicable. This string is set to whatever trails the type of HTMLScriptElements encountered upon initialization, iff their type starts with importmap.

Methods

Generated using TypeDoc