Skip to content

Commit

Permalink
Merge pull request jupyterlab#6980 from vidartf/vdom-ext-opt
Browse files Browse the repository at this point in the history
Make dependencies of VDOM extension optional
  • Loading branch information
jasongrout committed Aug 12, 2019
2 parents 9a34310 + 86ada79 commit b07d19d
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions packages/vdom-extension/src/index.ts
Expand Up @@ -34,14 +34,15 @@ const FACTORY_NAME = 'VDOM';

const plugin: JupyterFrontEndPlugin<IVDOMTracker> = {
id: '@jupyterlab/vdom-extension:factory',
requires: [IRenderMimeRegistry, INotebookTracker, ILayoutRestorer],
requires: [IRenderMimeRegistry],
optional: [INotebookTracker, ILayoutRestorer],
provides: IVDOMTracker,
autoStart: true,
activate: (
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry,
notebooks: INotebookTracker,
restorer: ILayoutRestorer
notebooks: INotebookTracker | null,
restorer: ILayoutRestorer | null
) => {
const tracker = new WidgetTracker<MimeDocument>({
namespace: 'vdom-widget'
Expand All @@ -57,23 +58,25 @@ const plugin: JupyterFrontEndPlugin<IVDOMTracker> = {
0
);

notebooks.widgetAdded.connect((sender, panel) => {
// Get the notebook's context and rendermime;
const {
context,
content: { rendermime }
} = panel;

// Add the renderer factory to the notebook's rendermime registry;
rendermime.addFactory(
{
safe: false,
mimeTypes: [MIME_TYPE],
createRenderer: options => new RenderedVDOM(options, context)
},
0
);
});
if (notebooks) {
notebooks.widgetAdded.connect((sender, panel) => {
// Get the notebook's context and rendermime;
const {
context,
content: { rendermime }
} = panel;

// Add the renderer factory to the notebook's rendermime registry;
rendermime.addFactory(
{
safe: false,
mimeTypes: [MIME_TYPE],
createRenderer: options => new RenderedVDOM(options, context)
},
0
);
});
}

app.docRegistry.addFileType({
name: 'vdom',
Expand All @@ -87,7 +90,7 @@ const plugin: JupyterFrontEndPlugin<IVDOMTracker> = {
dataType: 'json',
rendermime,
name: FACTORY_NAME,
primaryFileType: app.docRegistry.getFileType('vdom'),
primaryFileType: app.docRegistry.getFileType('vdom')!,
fileTypes: ['vdom', 'json'],
defaultFor: ['vdom']
});
Expand All @@ -102,15 +105,17 @@ const plugin: JupyterFrontEndPlugin<IVDOMTracker> = {
// Add widget factory to document registry.
app.docRegistry.addWidgetFactory(factory);

// Handle state restoration.
void restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({
path: widget.context.path,
factory: FACTORY_NAME
}),
name: widget => widget.context.path
});
if (restorer) {
// Handle state restoration.
void restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({
path: widget.context.path,
factory: FACTORY_NAME
}),
name: widget => widget.context.path
});
}

return tracker;
}
Expand Down

0 comments on commit b07d19d

Please sign in to comment.