Skip to content

Latest commit

 

History

History
101 lines (65 loc) · 2.54 KB

api.md

File metadata and controls

101 lines (65 loc) · 2.54 KB

SystemJS API

Core API (s.js & system.js)

System.constructor

Type: Function

This represents the System base class, which can be extended or reinstantiated to create a custom System instance.

Example:

  var clonedSystem = new System.constructor();
  clonedSystem.import('x'); // imports in a custom context

System.import(id [, parentURL]) -> Promise(Module)

Type: Function

Loads a module by name taking an optional normalized parent URL argument.

Promise resolves to the ES module namespace value.

Note: If provided, parentURL must be a valid URL, or URL resolution may break.

System.register(deps, declare)

Type: Function

Declaration function for defining modules of the System.register polyfill module format.

Read more on the format at the loader polyfill page

Note: Named System.register is not supported, only anonymous definitions.

System.resolve(id [, parentURL]) -> Promise(string)

Type: Function

Resolves a module specifier relative to an optional parent URL, returning the resolved URL.

Registry API (system.js only)

System.delete(id) -> Boolean

Type: Function

Deletes a module from the registry by ID.

Returns true if the module was found in the registry before deletion.

System.delete('http://site.com/normalized/module/name.js');

System.get(id) -> Module

Type: Function

Retrieve a loaded module from the registry by ID.

System.get('http://site.com/normalized/module/name.js').exportedFunction();

Module records with an error state will return null.

System.has(id) -> Boolean

Type: Function

Determine if a given ID is available in the loader registry.

Module records that have an error state in the registry still return true, while module records with in-progress loads will return false.

System.has('http://site.com/normalized/module/name.js');

System.set(id, module) -> Module

Type: Function

Sets a module in the registry by ID.

System.set('http://site.com/normalized/module/name.js', {
  exportedFunction: value
});

module is an object of names to set as the named exports.

If module is an existing Module Namespace, it will be used by reference.

System.entries() -> Iterator<[key, module]>

Type: Function

Allows you to retrieve all modules in the System registry. Each value will be an array with two values: a key and the module.

for (const [id, ns] of System.entries()) {
  console.log(id); // 'http://localhost/path-to-file.js'
  console.log(ns); // { exportName: 'value' }
};