From 5ed24fdff05e16afc50bd72c68b7c0379bd4ed58 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 18 May 2015 19:47:38 -0700 Subject: [PATCH] Use property on IPython/Jupyter global. This allow the loading to be lazy, and to display a warning message on access. --- notebook/static/base/js/namespace.js | 57 ++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/notebook/static/base/js/namespace.js b/notebook/static/base/js/namespace.js index fe7c2c3f2..d10a5e670 100644 --- a/notebook/static/base/js/namespace.js +++ b/notebook/static/base/js/namespace.js @@ -1,29 +1,56 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +// +// + var Jupyter = Jupyter || {}; + +var jprop = function(name, module_path){ + Object.defineProperty(Jupyter, name, { + get: function() { + console.warn('accessing `'+name+'` is deprecated. Use require("'+module_path+'")'); + return require(module_path); + }, + enumerable: true, + configurable: false + }); +} + +var jglobal = function(name, module_path){ + Object.defineProperty(Jupyter, name, { + get: function() { + console.warn('accessing `'+name+'` is deprecated. Use require("'+module_path+'").'+name); + return require(module_path)[name]; + }, + enumerable: true, + configurable: false + }); +} + define(function(){ "use strict"; // expose modules - Jupyter.utils = require('base/js/utils'); - Jupyter.load_extensions = Jupyter.utils.load_extensions; - - Jupyter.security = require('base/js/security'); - Jupyter.keyboard = require('base/js/keyboard'); - Jupyter.dialog = require('base/js/dialog'); + + jprop('utils','base/js/utils') + + //Jupyter.load_extensions = Jupyter.utils.load_extensions; + // + jprop('security','base/js/security'); + jprop('keyboard','base/js/keyboard'); + jprop('dialog','base/js/dialog'); - // exposed constructors - var comm = require('services/kernels/comm'); - Jupyter.CommManager = comm.CommManager; - Jupyter.Comm = comm.Comm; + //// exposed constructors + jglobal('CommManager','services/kernels/comm') + jglobal('Comm','services/kernels/comm') - Jupyter.NotificationWidget = require('base/js/notificationwidget').NotificationWidget; - Jupyter.Kernel = require('services/kernels/kernel').Kernel; - Jupyter.Session = require('services/kernels/session').Session; - Jupyter.LoginWidget = require('auth/js/loginwidget').LoginWidget - Jupyter.Page = require('base/js/page').Page; + jglobal('NotificationWidget','base/js/notificationwidget'); + jglobal('Kernel','services/kernels/kernel'); + jglobal('Session','services/sessions/session'); + jglobal('LoginWidget','auth/js/loginwidget'); + jglobal('Page','base/js/page'); Jupyter.version = "4.0.0.dev"; Jupyter._target = '_blank';