@garfish/bridge-react
Advanced tools
Comparing version 1.6.0-beta-20220526030938.0 to 1.6.0
@@ -25,7 +25,6 @@ var __defProp = Object.defineProperty; | ||
var defaultOpts = { | ||
rootComponent: null, | ||
loadRootComponent: null, | ||
rootComponent: void 0, | ||
loadRootComponent: void 0, | ||
renderType: void 0, | ||
errorBoundary: void 0, | ||
errorBoundaryClass: void 0, | ||
el: void 0, | ||
@@ -48,2 +47,5 @@ canUpdate: true, | ||
} | ||
if (opts.rootComponent && opts.loadRootComponent) { | ||
console.warn("garfish-react-bridge: `RootComponent` will be ignored for the reason you have passed both `rootComponent` and `loadRootComponent`."); | ||
} | ||
if (opts.errorBoundary && typeof opts.errorBoundary !== "function") { | ||
@@ -70,7 +72,12 @@ throw Error("The errorBoundary opt for garfish-react-bridge must either be omitted or be a function that returns React elements"); | ||
if (opts.loadRootComponent) { | ||
return opts.loadRootComponent(__spreadProps(__spreadValues({}, appInfo), { | ||
props | ||
})).then((resolvedComponent) => { | ||
opts.rootComponent = resolvedComponent; | ||
}); | ||
try { | ||
return opts.loadRootComponent(__spreadProps(__spreadValues({}, appInfo), { | ||
props | ||
})).then((resolvedComponent) => { | ||
opts.rootComponent = resolvedComponent; | ||
}); | ||
} catch (error) { | ||
console.error("error log by garfish: loadRootComponent error:", error); | ||
throw new Error(error); | ||
} | ||
} else { | ||
@@ -105,3 +112,3 @@ return Promise.resolve(); | ||
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) { | ||
const majorVersionString = React2.version.slice(0, React2.version.indexOf(".")); | ||
const majorVersionString = React2.version.split(".")[0]; | ||
try { | ||
@@ -129,7 +136,6 @@ return Number(majorVersionString) >= 16 && Number(majorVersionString) < 18; | ||
let elementToRender = rootComponentElement; | ||
if (opts.errorBoundary || opts.errorBoundaryClass) { | ||
opts.errorBoundaryClass = opts.errorBoundaryClass || opts.errorBoundaryClass || createErrorBoundary(opts); | ||
elementToRender = opts.React.createElement(opts.errorBoundaryClass, appInfo, elementToRender); | ||
if (opts.errorBoundary) { | ||
elementToRender = opts.React.createElement(createErrorBoundary(opts), appInfo, elementToRender); | ||
} | ||
return elementToRender; | ||
return rootComponentElement; | ||
} | ||
@@ -150,3 +156,3 @@ } | ||
const errorBoundary = opts.errorBoundary; | ||
return errorBoundary && errorBoundary(this.state.caughtError, this.state.caughtErrorInfo, this.props); | ||
return errorBoundary && errorBoundary(this.state.caughtError, this.props); | ||
} else { | ||
@@ -153,0 +159,0 @@ return this.props.children; |
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
type AppInfo = { | ||
type PropsInfo = { | ||
appName: string; | ||
@@ -12,17 +12,15 @@ dom: Element | ShadowRoot | Document; | ||
type LoadRootComponent<T> = (opts: AppInfo) => Promise<T>; | ||
type LoadRootComponent<T> = (opts: PropsInfo) => Promise<T>; | ||
type TypeComponent<T> = | ||
| { | ||
rootComponent: T | null; | ||
loadRootComponent?: LoadRootComponent<T> | null; | ||
rootComponent: T; | ||
loadRootComponent?: LoadRootComponent<T>; | ||
} | ||
| { | ||
rootComponent?: T | null; | ||
loadRootComponent: LoadRootComponent<T> | null; | ||
rootComponent?: T; | ||
loadRootComponent: LoadRootComponent<T>; | ||
}; | ||
type ErrorBoundary<T> = ( | ||
caughtError: boolean, | ||
info: string, | ||
caughtError: Error | any, | ||
props: any, | ||
@@ -45,5 +43,2 @@ ) => T | null; | ||
renderType: RenderTypes | (() => RenderTypes); | ||
errorBoundaryClass: | ||
| HTMLElement | ||
| { (this: any, props: any): void; prototype: any }; | ||
el: string; | ||
@@ -59,3 +54,3 @@ canUpdate: boolean; // by default, allow parcels created with garfish-react-bridge to be updated | ||
declare type Options = UserOptions<typeof React, typeof ReactDOM, React.ComponentType, React.ReactNode>; | ||
declare type Options = UserOptions<typeof React, typeof ReactDOM, any, React.ReactNode>; | ||
declare global { | ||
@@ -71,2 +66,2 @@ interface Window { | ||
export { AppInfo, reactBridge }; | ||
export { PropsInfo, reactBridge }; |
@@ -51,7 +51,6 @@ var __create = Object.create; | ||
var defaultOpts = { | ||
rootComponent: null, | ||
loadRootComponent: null, | ||
rootComponent: void 0, | ||
loadRootComponent: void 0, | ||
renderType: void 0, | ||
errorBoundary: void 0, | ||
errorBoundaryClass: void 0, | ||
el: void 0, | ||
@@ -74,2 +73,5 @@ canUpdate: true, | ||
} | ||
if (opts.rootComponent && opts.loadRootComponent) { | ||
console.warn("garfish-react-bridge: `RootComponent` will be ignored for the reason you have passed both `rootComponent` and `loadRootComponent`."); | ||
} | ||
if (opts.errorBoundary && typeof opts.errorBoundary !== "function") { | ||
@@ -96,7 +98,12 @@ throw Error("The errorBoundary opt for garfish-react-bridge must either be omitted or be a function that returns React elements"); | ||
if (opts.loadRootComponent) { | ||
return opts.loadRootComponent(__spreadProps(__spreadValues({}, appInfo), { | ||
props | ||
})).then((resolvedComponent) => { | ||
opts.rootComponent = resolvedComponent; | ||
}); | ||
try { | ||
return opts.loadRootComponent(__spreadProps(__spreadValues({}, appInfo), { | ||
props | ||
})).then((resolvedComponent) => { | ||
opts.rootComponent = resolvedComponent; | ||
}); | ||
} catch (error) { | ||
console.error("error log by garfish: loadRootComponent error:", error); | ||
throw new Error(error); | ||
} | ||
} else { | ||
@@ -131,3 +138,3 @@ return Promise.resolve(); | ||
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) { | ||
const majorVersionString = React2.version.slice(0, React2.version.indexOf(".")); | ||
const majorVersionString = React2.version.split(".")[0]; | ||
try { | ||
@@ -155,7 +162,6 @@ return Number(majorVersionString) >= 16 && Number(majorVersionString) < 18; | ||
let elementToRender = rootComponentElement; | ||
if (opts.errorBoundary || opts.errorBoundaryClass) { | ||
opts.errorBoundaryClass = opts.errorBoundaryClass || opts.errorBoundaryClass || createErrorBoundary(opts); | ||
elementToRender = opts.React.createElement(opts.errorBoundaryClass, appInfo, elementToRender); | ||
if (opts.errorBoundary) { | ||
elementToRender = opts.React.createElement(createErrorBoundary(opts), appInfo, elementToRender); | ||
} | ||
return elementToRender; | ||
return rootComponentElement; | ||
} | ||
@@ -176,3 +182,3 @@ } | ||
const errorBoundary = opts.errorBoundary; | ||
return errorBoundary && errorBoundary(this.state.caughtError, this.state.caughtErrorInfo, this.props); | ||
return errorBoundary && errorBoundary(this.state.caughtError, this.props); | ||
} else { | ||
@@ -179,0 +185,0 @@ return this.props.children; |
{ | ||
"name": "@garfish/bridge-react", | ||
"version": "1.6.0-beta-20220526030938.0", | ||
"version": "1.6.0", | ||
"description": "garfish module.", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
}, | ||
"readme": "# `@garfish/bridge`\n\n[![NPM version](https://img.shields.io/npm/v/@garfish/bridge.svg?style=flat-square)](https://www.npmjs.com/package/@garfish/bridge)\n\n## Usage\n\n```jsx\n// child app\nimport { reactBridge } from '@garfish/bridge-react';\nfunction App() {\n return <div>content</div>;\n}\n\nreactBridge({\n el: '#root',\n rootComponent: App,\n});\n```\n" | ||
"readme": "# `@garfish/bridge`\n\n[![NPM version](https://img.shields.io/npm/v/@garfish/bridge.svg?style=flat-square)](https://www.npmjs.com/package/@garfish/bridge)\n\n## Usage\n\n```jsx\n// child app\nimport { reactBridge } from '@garfish/bridge-react';\nfunction App() {\n return <div>content</div>;\n}\nexport const provider = reactBridge({\n el: '#root',\n rootComponent: App,\n});\n```\n" | ||
} |
@@ -13,4 +13,3 @@ # `@garfish/bridge` | ||
} | ||
reactBridge({ | ||
export const provider = reactBridge({ | ||
el: '#root', | ||
@@ -17,0 +16,0 @@ rootComponent: App, |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19611
437
0
18