mirror of
https://github.com/systemjs/systemjs.git
synced 2026-02-01 15:59:54 +00:00
document registerKey argument
This commit is contained in:
parent
117fd2baf2
commit
4b73d6d4a9
@ -17,7 +17,7 @@ As of SystemJS 0.20, instantiation plugins are modules with a `load` method reso
|
||||
|
||||
plugin.js
|
||||
```javascript
|
||||
export function load (key) {
|
||||
export function load (url) {
|
||||
return Promise.resolve({
|
||||
some: 'value'
|
||||
});
|
||||
@ -35,7 +35,15 @@ Within this hook, plugins can fetch `key` as a source text, or do any other cust
|
||||
is provided, an empty module is used for the plugin module value.
|
||||
|
||||
Within the `load` hook `this` is set to the loader itself. It is also possible to call `loader.register(key, deps, declare)` to instantiate the module
|
||||
in the plugin load hook.
|
||||
in the plugin load hook. Because plugins are referenced via syntax (`resource!plugin`) it is necessary to use the corresponding `registerKey` argument here:
|
||||
|
||||
```javascript
|
||||
export function load (url, registerKey) {
|
||||
this.register(registerKey, deps, function (_export, _context) {
|
||||
// ... System.register format ...
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
> For SystemJS 0.19 and below, instantiation plugins must use the `instantiate` hook API form from the compiler plugins section below.
|
||||
|
||||
@ -45,11 +53,11 @@ A CSS loading plugin can be written:
|
||||
|
||||
css.js:
|
||||
```javascript
|
||||
exports.load = function(key) {
|
||||
exports.load = function (url) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = key;
|
||||
link.href = url;
|
||||
link.onload = resolve;
|
||||
|
||||
document.head.appendChild(link);
|
||||
|
||||
@ -42,7 +42,7 @@ export function instantiate (key, metadata, processAnonRegister) {
|
||||
.then(function () {
|
||||
// modern plugin = load hook
|
||||
if (metadata.pluginModule && typeof metadata.pluginModule.load === 'function')
|
||||
return runPluginLoad(loader, key, metadata, metadata.pluginKey, metadata.pluginModule);
|
||||
return runPluginLoad(loader, metadata.pluginArgument, key, metadata, metadata.pluginKey, metadata.pluginModule);
|
||||
return runFetchPipeline(loader, key, metadata, processAnonRegister, config.wasm);
|
||||
})
|
||||
|
||||
@ -95,10 +95,10 @@ function protectedCreateNamespace (bindings) {
|
||||
return new ModuleNamespace(bindings);
|
||||
}
|
||||
|
||||
function runPluginLoad (loader, key, metadata, pluginKey, pluginModule) {
|
||||
function runPluginLoad (loader, key, registerKey, metadata, pluginKey, pluginModule) {
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return pluginModule.load.call(loader, key);
|
||||
return pluginModule.load.call(loader, key, registerKey);
|
||||
})
|
||||
.then(function (pluginResult) {
|
||||
if (pluginResult === undefined)
|
||||
@ -501,7 +501,7 @@ function transpile (loader, source, key, metadata) {
|
||||
return loader.import.call(loader, loader.transpiler)
|
||||
.then(function (transpiler) {
|
||||
if (typeof transpiler.load === 'function')
|
||||
return runPluginLoad(loader, key, metadata, loader.transpiler, transpiler);
|
||||
return runPluginLoad(loader, key, key, metadata, loader.transpiler, transpiler);
|
||||
|
||||
if (transpiler.__useDefault)
|
||||
transpiler = transpiler.default;
|
||||
|
||||
@ -530,8 +530,8 @@ suite('SystemJS Standard Tests', function() {
|
||||
|
||||
test('Instantiate plugin register', function () {
|
||||
System.set('instantiate-plugin-register', System.newModule({
|
||||
load: function (key) {
|
||||
this.register(key, [], function (_export) {
|
||||
load: function (key, fullKey) {
|
||||
this.register(fullKey, [], function (_export) {
|
||||
return function () {
|
||||
_export('some', 'thing');
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user