react-arbiter
Advanced tools
Comparing version 0.4.1 to 0.5.0
# React Arbiter Changelog | ||
## 0.5.0 | ||
- Throw `MODULE_NOT_FOUND` error if module cannot be found | ||
- Support for `sourceURL` added | ||
- Added `isfunc` utility | ||
## 0.4.1 | ||
@@ -4,0 +10,0 @@ |
@@ -28,3 +28,3 @@ "use strict"; | ||
this.mounted = true; | ||
if (typeof fetchModules === 'function') { | ||
if (utils_1.isfunc(fetchModules)) { | ||
utils_1.loadModules(fetchModules, fetchDependency, dependencies, getDependencies, cache).then(modules => this.mounted && this.finish(undefined, modules), error => this.mounted && this.finish(error, [])); | ||
@@ -39,3 +39,3 @@ } | ||
const { loaded, modules, error } = this.state; | ||
if (typeof children === 'function') { | ||
if (utils_1.isfunc(children)) { | ||
return children(loaded, modules, error); | ||
@@ -42,0 +42,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const React = require("react"); | ||
const utils_1 = require("../utils"); | ||
/** | ||
@@ -17,3 +18,3 @@ * Represents an arbiter stasis component to prevent extension components | ||
const { onError } = this.props; | ||
if (typeof onError === 'function') { | ||
if (utils_1.isfunc(onError)) { | ||
onError(error); | ||
@@ -26,6 +27,6 @@ } | ||
render() { | ||
const { children, renderError } = this.props; | ||
const { children, renderError, renderChild } = this.props; | ||
const { error } = this.state; | ||
if (error) { | ||
if (typeof renderError === 'function') { | ||
if (utils_1.isfunc(renderError)) { | ||
return renderError(error); | ||
@@ -35,5 +36,5 @@ } | ||
} | ||
return children; | ||
return utils_1.isfunc(renderChild) ? renderChild(children) : children; | ||
} | ||
} | ||
exports.ArbiterStasis = ArbiterStasis; |
@@ -109,2 +109,6 @@ import { ComponentType, Ref } from 'react'; | ||
renderError?(error: Error): React.ReactNode; | ||
/** | ||
* Place a renderer here to customize the normal output. | ||
*/ | ||
renderChild?(child: React.ReactNode): React.ReactNode; | ||
} | ||
@@ -111,0 +115,0 @@ export interface WrapComponentOptions<T> extends StasisOptions { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const setup_1 = require("./setup"); | ||
const isfunc_1 = require("./isfunc"); | ||
const defaultGlobalDependencies = {}; | ||
@@ -25,3 +26,3 @@ const defaultGetDependencies = () => false; | ||
function loadModules(fetchModules, fetchDependency = fetch_1.defaultFetchDependency, globalDependencies = defaultGlobalDependencies, getLocalDependencies = defaultGetDependencies, cache = defaultCache) { | ||
if (typeof fetchModules === 'function') { | ||
if (isfunc_1.isfunc(fetchModules)) { | ||
const getDependencies = target => { | ||
@@ -47,3 +48,3 @@ return getLocalDependencies(target) || globalDependencies; | ||
function setupModules(createApi, modules) { | ||
if (typeof createApi === 'function') { | ||
if (isfunc_1.isfunc(createApi)) { | ||
for (const app of modules) { | ||
@@ -50,0 +51,0 @@ const api = createApi(app); |
@@ -6,6 +6,7 @@ import { ArbiterModuleApp, AvailableDependencies } from '../types'; | ||
* @param content The content of the dependency to compile. | ||
* @param link The optional link to the dependency. | ||
* @param dependencies The globally available dependencies. | ||
* @returns The evaluated dependency. | ||
*/ | ||
export declare function evalDependency<TApi>(name: string, content: string, dependencies?: AvailableDependencies): ArbiterModuleApp<TApi> | undefined; | ||
export declare function evalDependency<TApi>(name: string, content: string, link?: string, dependencies?: AvailableDependencies): ArbiterModuleApp<TApi> | undefined; | ||
/** | ||
@@ -15,5 +16,6 @@ * Compiles the given content from a module with a dependency resolution. | ||
* @param content The content of the dependency to compile. | ||
* @param link The optional link to the dependency. | ||
* @param dependencies The globally available dependencies. | ||
* @returns The evaluated module. | ||
*/ | ||
export declare function compileDependency<TApi>(name: string, content: string, dependencies: AvailableDependencies): ArbiterModuleApp<TApi>; | ||
export declare function compileDependency<TApi>(name: string, content: string, link?: string, dependencies?: AvailableDependencies): ArbiterModuleApp<TApi>; |
@@ -6,3 +6,5 @@ "use strict"; | ||
if (!dependency) { | ||
console.error('Cannot find the required module!', name, dependencies); | ||
const error = new Error(`Cannot find module '${name}'`); | ||
error.code = 'MODULE_NOT_FOUND'; | ||
throw error; | ||
} | ||
@@ -15,6 +17,7 @@ return dependency; | ||
* @param content The content of the dependency to compile. | ||
* @param link The optional link to the dependency. | ||
* @param dependencies The globally available dependencies. | ||
* @returns The evaluated dependency. | ||
*/ | ||
function evalDependency(name, content, dependencies = {}) { | ||
function evalDependency(name, content, link = '', dependencies = {}) { | ||
const mod = { | ||
@@ -25,3 +28,4 @@ exports: {}, | ||
try { | ||
const importer = new Function('module', 'exports', 'require', content); | ||
const sourceUrl = link && `\n//# sourceURL=${link}`; | ||
const importer = new Function('module', 'exports', 'require', content + sourceUrl); | ||
importer(mod, mod.exports, require); | ||
@@ -39,7 +43,8 @@ } | ||
* @param content The content of the dependency to compile. | ||
* @param link The optional link to the dependency. | ||
* @param dependencies The globally available dependencies. | ||
* @returns The evaluated module. | ||
*/ | ||
function compileDependency(name, content, dependencies) { | ||
const app = evalDependency(name, content, dependencies); | ||
function compileDependency(name, content, link = '', dependencies = {}) { | ||
const app = evalDependency(name, content, link, dependencies); | ||
if (!app) { | ||
@@ -46,0 +51,0 @@ console.error('Invalid module found.', name); |
@@ -5,3 +5,4 @@ export * from './aggregate'; | ||
export * from './fetch'; | ||
export * from './isfunc'; | ||
export * from './load'; | ||
export * from './setup'; |
@@ -10,3 +10,4 @@ "use strict"; | ||
__export(require("./fetch")); | ||
__export(require("./isfunc")); | ||
__export(require("./load")); | ||
__export(require("./setup")); |
@@ -19,3 +19,3 @@ "use strict"; | ||
for (const item of dependencyMap) { | ||
dependencies[item.name] = dependency_1.evalDependency(item.name, item.content, dependencies); | ||
dependencies[item.name] = dependency_1.evalDependency(item.name, item.content, item.url, dependencies); | ||
} | ||
@@ -25,5 +25,5 @@ return dependencies; | ||
} | ||
function loadFromContent(meta, content, fetchDependency, getDependencies) { | ||
function loadFromContent(meta, content, fetchDependency, getDependencies, link) { | ||
return loadDependencies(meta, fetchDependency, getDependencies).then(dependencies => { | ||
const app = dependency_1.compileDependency(meta.name, content, dependencies); | ||
const app = dependency_1.compileDependency(meta.name, content, link, dependencies); | ||
return Object.assign({}, app, meta); | ||
@@ -46,3 +46,3 @@ }, error => { | ||
if (link) { | ||
return fetchDependency(link).then(content => loadFromContent(meta, content, fetchDependency, getDependencies)); | ||
return fetchDependency(link).then(content => loadFromContent(meta, content, fetchDependency, getDependencies, link)); | ||
} | ||
@@ -49,0 +49,0 @@ else if (content) { |
@@ -14,2 +14,3 @@ "use strict"; | ||
const components_1 = require("../components"); | ||
const utils_1 = require("../utils"); | ||
function createForeignComponentContainer(contextTypes = ['router']) { | ||
@@ -62,3 +63,3 @@ var _a; | ||
const argRender = argAsReact.prototype && argAsReact.prototype.render; | ||
if (typeof argRender === 'function' || argAsReact.displayName) { | ||
if (utils_1.isfunc(argRender) || argAsReact.displayName) { | ||
return wrapReactComponent(argAsReact, stasisOptions, forwardProps); | ||
@@ -65,0 +66,0 @@ } |
{ | ||
"name": "react-arbiter", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Recall all your modules to extend your SPA dynamically at runtime.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
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
73910
47
1007