Skip to content

Commit 9f5926e

Browse files
authored
Merge pull request #2710 from takluyver/initialized_promise
Add a promise for app_initialized event.
2 parents 18c20d1 + 1812469 commit 9f5926e

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
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+
// });
11+
12+
define(['base/js/events', 'base/js/namespace'], function(events, Jupyter) {
13+
"use strict";
14+
15+
// Promise to be resolved when the application is initialized.
16+
// The value is the name of the app on the current page.
17+
var app_initialized = new Promise(function(resolve, reject) {
18+
events.on('app_initialized.NotebookApp', function() {
19+
resolve('NotebookApp');
20+
});
21+
events.on('app_initialized.DashboardApp', function() {
22+
resolve('DashboardApp');
23+
});
24+
});
25+
26+
var promises = {
27+
app_initialized: app_initialized
28+
};
29+
Jupyter.promises = promises;
30+
31+
return promises;
32+
});

notebook/static/custom/custom.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
* Instances are created after the loading of this file and might need to be accessed using events:
2121
* define([
2222
* 'base/js/namespace',
23-
* 'base/js/events'
24-
* ], function(IPython, events) {
25-
* events.on("app_initialized.NotebookApp", function () {
23+
* 'base/js/promises'
24+
* ], function(IPython, promises) {
25+
* promises.app_initialized.then(function (appName) {
26+
* if (appName !== 'NotebookApp') return;
2627
* IPython.keyboard_manager....
2728
* });
2829
* });
@@ -34,9 +35,10 @@
3435
*
3536
* define([
3637
* 'base/js/namespace',
37-
* 'base/js/events'
38-
* ], function(IPython, events) {
39-
* events.on('app_initialized.NotebookApp', function(){
38+
* 'base/js/promises'
39+
* ], function(IPython, promises) {
40+
* promises.app_initialized.then(function (appName) {
41+
* if (appName !== 'NotebookApp') return;
4042
* IPython.toolbar.add_buttons_group([
4143
* {
4244
* 'label' : 'run qtconsole',

notebook/static/notebook/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require([
2929
'base/js/utils',
3030
'base/js/page',
3131
'base/js/events',
32+
'base/js/promises',
3233
'auth/js/loginwidget',
3334
'notebook/js/maintoolbar',
3435
'notebook/js/pager',
@@ -52,6 +53,7 @@ require([
5253
utils,
5354
page,
5455
events,
56+
promises,
5557
loginwidget,
5658
maintoolbar,
5759
pager,

notebook/static/tree/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require([
2626
'base/js/namespace',
2727
'base/js/dialog',
2828
'base/js/events',
29+
'base/js/promises',
2930
'base/js/page',
3031
'base/js/utils',
3132
'services/config',
@@ -41,6 +42,7 @@ require([
4142
IPython,
4243
dialog,
4344
events,
45+
promises,
4446
page,
4547
utils,
4648
config,

0 commit comments

Comments
 (0)