Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore cloned output #5981

Merged
merged 7 commits into from Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 28 additions & 26 deletions packages/apputils/src/instancetracker.ts
Expand Up @@ -52,6 +52,19 @@ export interface IInstanceTracker<T extends Widget> extends IDisposable {
*/
readonly size: number;

/**
* A promise that is resolved when the instance tracker has been
* restored from a serialized state.
*
* #### Notes
* Most client code will not need to use this, since they can wait
* for the whole application to restore. However, if an extension
* wants to perform actions during the application restoration, but
* after the restoration of another instance tracker, they can use
* this promise.
*/
readonly restored: Promise<void>;

/**
* Find the first widget in the tracker that satisfies a filter function.
*
Expand Down Expand Up @@ -325,7 +338,7 @@ export class InstanceTracker<T extends Widget>
* multiple instance trackers and, when ready, asks them each to restore their
* respective widgets.
*/
restore(options: InstanceTracker.IRestoreOptions<T>): Promise<any> {
async restore(options: InstanceTracker.IRestoreOptions<T>): Promise<any> {
const { command, registry, state, when } = options;
const namespace = this.namespace;
const promises = when
Expand All @@ -334,36 +347,25 @@ export class InstanceTracker<T extends Widget>

this._restore = options;

return Promise.all(promises)
.then(([saved]) => {
return Promise.all(
saved.ids.map((id, index) => {
const value = saved.values[index];
const args = value && (value as any).data;
if (args === undefined) {
return state.remove(id);
}

// Execute the command and if it fails, delete the state restore data.
return registry
.execute(command, args)
.catch(() => state.remove(id));
})
);
const [saved] = await Promise.all(promises);
const val = await Promise.all(
saved.ids.map((id, index) => {
const value = saved.values[index];
const args = value && (value as any).data;
if (args === undefined) {
return state.remove(id);
}

// Execute the command and if it fails, delete the state restore data.
return registry.execute(command, args).catch(() => state.remove(id));
})
.then(val => {
this._restored.resolve(void 0);
return val;
});
);
this._restored.resolve(void 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using undefined now, could we change this to undefined instead of void 0.

Also since Promise.all resolves with an array, could we call it values instead of a singular?

return val;
}

/**
* A promise resolved when the instance tracker has been restored.
*
* #### Notes
* This promise is not exposed on the IInstanceTracker interface.
* It is intended to allow for the owner/creator of an instance tracker
* to perform additional actions after restoration in specialized use-cases.
*/
get restored(): Promise<void> {
return this._restored.promise;
Expand Down
2 changes: 1 addition & 1 deletion packages/notebook-extension/src/index.ts
Expand Up @@ -536,7 +536,7 @@ function activateNotebookHandler(
index: widget.content.index
}),
name: widget => `${widget.content.path}:${widget.content.index}`,
when: tracker.restored
when: tracker.restored // After the notebook widgets (but not contents).
});
}

Expand Down