Skip to content

Commit e37b697

Browse files
committed
Add promise for notebook_loaded.Notebook event
1 parent 9f5926e commit e37b697

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

notebook/static/base/js/promises.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
// Give us an object to bind all events to. This object should be created
5-
// before all other objects so it exists when others register event handlers.
6-
// To register an event handler:
7-
//
8-
// require(['base/js/events'], function (events) {
9-
// events.on("event.Namespace", function () { do_stuff(); });
10-
// });
4+
// Define an object to attach promises to for one-time events.
115

126
define(['base/js/events', 'base/js/namespace'], function(events, Jupyter) {
137
"use strict";

notebook/static/notebook/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require([
3333
'auth/js/loginwidget',
3434
'notebook/js/maintoolbar',
3535
'notebook/js/pager',
36+
'notebook/js/promises',
3637
'notebook/js/quickhelp',
3738
'notebook/js/menubar',
3839
'notebook/js/notificationarea',
@@ -57,6 +58,7 @@ require([
5758
loginwidget,
5859
maintoolbar,
5960
pager,
61+
nb_promises,
6062
quickhelp,
6163
menubar,
6264
notificationarea,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
// Define promises for notebook events.
5+
6+
define(['base/js/events', 'base/js/promises'], function(events, promises) {
7+
"use strict";
8+
9+
// Promise to be resolved when the notebook is *initially* loaded.
10+
// The event may fire again if the notebook is reloaded later, but this
11+
// promise only tracks the initial load.
12+
promises.notebook_loaded = new Promise(function(resolve, reject) {
13+
events.one('notebook_loaded.Notebook', function() {
14+
resolve();
15+
});
16+
events.one('notebook_load_failed.Notebook', function() {
17+
reject();
18+
});
19+
});
20+
21+
return promises;
22+
});

0 commit comments

Comments
 (0)