Jelajahi Sumber

Use the jupyter namespace

Steven Silvester 8 tahun lalu
induk
melakukan
8942ff1218
4 mengubah file dengan 20 tambahan dan 19 penghapusan
  1. 2 3
      jupyterlab/lab.html
  2. 15 14
      jupyterlab/loader.js
  3. 1 1
      jupyterlab/plugin.js
  4. 2 1
      jupyterlab/webpack.config.js

+ 2 - 3
jupyterlab/lab.html

@@ -28,9 +28,8 @@ Distributed under the terms of the Modified BSD License.
 }</script>
 <script src="{{static_prefix}}/loader.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script>
-jupyterEnsure('lab/jupyterlab.bundle.js', function(requireFunc) {
-  console.log('bundle loaded', requireFunc);
-  jupyterRequire("jupyterlab-extension@0.1.0/index.js");
+jupyter.ensure('lab/jupyterlab.bundle.js', function(requireFunc) {
+  requireFunc("jupyterlab-extension@0.1.0/index.js");
 });
 </script>
 </body>

+ 15 - 14
jupyterlab/loader.js

@@ -19,14 +19,14 @@ var installedChunks = {
 };
 
 
-// Define a jupyter module.
-function jupyterDefine(name, callback) {
+// Define a module.
+function defineModule(name, callback) {
   registered[name] = callback;
 }
 
 
-// Require a jupyter module that has already been loaded.
-function jupyterRequire(moduleRequest) {
+// Require a module that has already been loaded.
+function requireModule(moduleRequest) {
   // Check if module is in cache
   var moduleId = findModuleId(moduleRequest)
   if(installedModules[moduleId])
@@ -40,7 +40,7 @@ function jupyterRequire(moduleRequest) {
   };
 
   // Execute the module function
-  registered[moduleId].call(module.exports, module, module.exports, jupyterRequire);
+  registered[moduleId].call(module.exports, module, module.exports, requireModule);
 
   // Flag the module as loaded
   module.loaded = true;
@@ -50,11 +50,11 @@ function jupyterRequire(moduleRequest) {
 }
 
 
-// Ensure a jupyter bundle is loaded on a page.
-function jupyterEnsure(path, callback) {
+// Ensure a bundle is loaded on a page.
+function ensureBundle(path, callback) {
   // "0" is the signal for "already loaded"
   if (installedChunks[path] === 0) {
-    return callback.call(null, jupyterRequire);
+    return callback.call(null, requireModule);
   }
 
   // an array means "currently loading".
@@ -73,7 +73,7 @@ function jupyterEnsure(path, callback) {
   script.onload = function() {
     var callbacks = installedChunks[path];
     while(callbacks.length)
-      callbacks.shift().call(null, jupyterRequire);
+      callbacks.shift().call(null, requireModule);
     installedChunks[path] = 0;
   }
   head.appendChild(script);
@@ -125,9 +125,10 @@ function findModuleId(name) {
   return matches[index];
 }
 
-// Add the functions to window.
-jupyterRequire.e = jupyterEnsure;
+requireModule.e = ensureBundle;
 
-window.jupyterDefine = jupyterDefine;
-window.jupyterRequire = jupyterRequire;
-window.jupyterEnsure = jupyterEnsure;
+module.exports = {
+  define: defineModule,
+  ensure: ensureBundle,
+  require: requireModule
+}

+ 1 - 1
jupyterlab/plugin.js

@@ -272,7 +272,7 @@ function parseModule(compilation, module, pluginName, publicPath) {
   source = source.split('__webpack_require__').join(requireName);
 
   // Create our header with a version-mangled defined name.
-  var header = defineName + '("' + getDefineName(module);
+  var header = pluginName + '.define("' + getDefineName(module);
   header += '", function (module, exports, ' + requireName + ') {\n';
 
   // Combine code indent.

+ 2 - 1
jupyterlab/webpack.config.js

@@ -57,7 +57,8 @@ module.exports = [{
   output: {
     path: __dirname + '/build',
     filename: '[name].bundle.js',
-    libraryTarget: 'this'
+    libraryTarget: 'this',
+    library: 'jupyter'
   },
   node: {
     fs: 'empty'