jupyter-js-utils
Advanced tools
Comparing version 0.3.5 to 0.4.0
@@ -136,9 +136,9 @@ /** | ||
/** | ||
* Try to load a class. | ||
* Try to load an object from a module or a registry. | ||
* | ||
* Try to load a class from a module asynchronously, if a module | ||
* is specified, otherwise tries to load a class from the global | ||
* Try to load an object from a module asynchronously if a module | ||
* is specified, otherwise tries to load an object from the global | ||
* registry, if the global registry is provided. | ||
*/ | ||
export declare function loadClass(className: string, moduleName: string, registry?: { | ||
export declare function loadObject(name: string, moduleName: string, registry?: { | ||
[key: string]: any; | ||
@@ -145,0 +145,0 @@ }): Promise<any>; |
@@ -187,19 +187,22 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* Try to load a class. | ||
* Try to load an object from a module or a registry. | ||
* | ||
* Try to load a class from a module asynchronously, if a module | ||
* is specified, otherwise tries to load a class from the global | ||
* Try to load an object from a module asynchronously if a module | ||
* is specified, otherwise tries to load an object from the global | ||
* registry, if the global registry is provided. | ||
*/ | ||
function loadClass(className, moduleName, registry) { | ||
function loadObject(name, moduleName, registry) { | ||
return new Promise(function (resolve, reject) { | ||
// Try loading the view module using require.js | ||
if (moduleName) { | ||
if (typeof requirejs === 'undefined') { | ||
throw new Error('requirejs not found.'); | ||
} | ||
requirejs([moduleName], function (mod) { | ||
if (mod[className] === void 0) { | ||
var msg = "Class " + className + " not found in module " + moduleName; | ||
if (mod[name] === void 0) { | ||
var msg = "Object '" + name + "' not found in module '" + moduleName + "'"; | ||
reject(new Error(msg)); | ||
} | ||
else { | ||
resolve(mod[className]); | ||
resolve(mod[name]); | ||
} | ||
@@ -209,7 +212,7 @@ }, reject); | ||
else { | ||
if (registry && registry[className]) { | ||
resolve(registry[className]); | ||
if (registry && registry[name]) { | ||
resolve(registry[name]); | ||
} | ||
else { | ||
reject(new Error("Class " + className + " not found in registry")); | ||
reject(new Error("Object '" + name + "' not found in registry")); | ||
} | ||
@@ -219,3 +222,3 @@ } | ||
} | ||
exports.loadClass = loadClass; | ||
exports.loadObject = loadObject; | ||
; | ||
@@ -222,0 +225,0 @@ /** |
{ | ||
"name": "jupyter-js-utils", | ||
"version": "0.3.5", | ||
"version": "0.4.0", | ||
"description": "JavaScript utilities for the Jupyter frontend", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"clean": "rimraf docs && rimraf lib && rimraf test/build", | ||
"clean": "rimraf docs && rimraf lib && rimraf test/build && rimraf test/coverage", | ||
"build:src": "tsc --project src", | ||
@@ -28,4 +28,5 @@ "build:test": "tsc --project test/src", | ||
"prepublish": "npm run build", | ||
"test:coverage": "cd test && istanbul cover _mocha -- build/index.js --foo bar", | ||
"test": "mocha test/build/index.js --foo bar" | ||
"test:coverage": "istanbul cover --dir test/coverage _mocha -- test/build/test*.js --foo bar", | ||
"test:debug": "mocha test/build/test*.js --foo bar --debug-brk", | ||
"test": "mocha test/build/test*.js --foo bar" | ||
}, | ||
@@ -32,0 +33,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47274
9
1493
1