document registerKey argument

This commit is contained in:
guybedford 2016-11-14 17:37:29 +02:00
parent 117fd2baf2
commit 4b73d6d4a9
3 changed files with 18 additions and 10 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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');
};