Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions notebook/static/base/js/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

// Give us an object to bind all events to. This object should be created
// before all other objects so it exists when others register event handlers.
// To register an event handler:
//
// require(['base/js/events'], function (events) {
// events.on("event.Namespace", function () { do_stuff(); });
// });

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

// Promise to be resolved when the application is initialized.
// The value is the name of the app on the current page.
var app_initialized = new Promise(function(resolve, reject) {
events.on('app_initialized.NotebookApp', function() {
resolve('NotebookApp');
});
events.on('app_initialized.DashboardApp', function() {
resolve('DashboardApp');
});
});

var promises = {
app_initialized: app_initialized
};
Jupyter.promises = promises;

return promises;
});
14 changes: 8 additions & 6 deletions notebook/static/custom/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
* Instances are created after the loading of this file and might need to be accessed using events:
* define([
* 'base/js/namespace',
* 'base/js/events'
* ], function(IPython, events) {
* events.on("app_initialized.NotebookApp", function () {
* 'base/js/promises'
* ], function(IPython, promises) {
* promises.app_initialized.then(function (appName) {
* if (appName !== 'NotebookApp') return;
* IPython.keyboard_manager....
* });
* });
Expand All @@ -34,9 +35,10 @@
*
* define([
* 'base/js/namespace',
* 'base/js/events'
* ], function(IPython, events) {
* events.on('app_initialized.NotebookApp', function(){
* 'base/js/promises'
* ], function(IPython, promises) {
* promises.app_initialized.then(function (appName) {
* if (appName !== 'NotebookApp') return;
* IPython.toolbar.add_buttons_group([
* {
* 'label' : 'run qtconsole',
Expand Down
2 changes: 2 additions & 0 deletions notebook/static/notebook/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require([
'base/js/utils',
'base/js/page',
'base/js/events',
'base/js/promises',
'auth/js/loginwidget',
'notebook/js/maintoolbar',
'notebook/js/pager',
Expand All @@ -52,6 +53,7 @@ require([
utils,
page,
events,
promises,
loginwidget,
maintoolbar,
pager,
Expand Down
2 changes: 2 additions & 0 deletions notebook/static/tree/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require([
'base/js/namespace',
'base/js/dialog',
'base/js/events',
'base/js/promises',
'base/js/page',
'base/js/utils',
'services/config',
Expand All @@ -41,6 +42,7 @@ require([
IPython,
dialog,
events,
promises,
page,
utils,
config,
Expand Down