documentationenhancementhelp wanted
Description
Description
This was originally reported on phosphor.
Paraphrasing the issue: We should document how a token would extend another token. In other words, (the object registered with) token B implements the interface of (the object registered with) token A, plus some extra stuff. Normal plugins would require token A, but some might require token B. It would be nice if the dependency injection framework could register that token B could be served to those requesting token A.
@vidartf suggested this pattern:
// File defining tokens
import {TokenA} from 'amodule';
import {Token} from '@phosphor/...';
export interface TokenB extends TokenA {
myProp: string;
}
export const TokenB = new Token(...);
// File defining plugins
import {TokenA, activateA} from 'amodule';
import {TokenB} from 'bmodule/lib/tokens';
const MyPluginB = {
provides: TokenB;
activate: (...) => {
const A = activateA(...);
A.myProp = 'foo!';
return A;
}
}
const MyPluginA = {
provides: TokenA;
requires: [TokenB];
activate: (..., B: TokenB) => {
return B;
}
}
export {MyPluginA, MyPluginB};
This should be documented on the extension dev page.