UNPKG

piral-core

Version:

The core library for creating a Piral instance.

30 lines 1.55 kB
import * as React from 'react'; import { ErrorBoundary, wrapComponent } from '../components'; import { defaultRender } from '../utils'; const DefaultWrapper = (props) => defaultRender(props.children); function getWrapper(wrappers, wrapperType) { const WrapAll = wrappers['*']; const WrapType = wrappers[wrapperType]; if (WrapAll && WrapType) { return (props) => (React.createElement(WrapAll, { ...props }, React.createElement(WrapType, { ...props }))); } return WrapType || WrapAll || DefaultWrapper; } function makeWrapper(context, outerProps, wrapperType, errorType) { const wrapped = context.readState((m) => m.app.wrap); const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType)); const Wrapper = (props) => (React.createElement(OuterWrapper, { ...outerProps, ...props }, React.createElement(ErrorBoundary, { ...outerProps, ...props, errorType: errorType }, props.children))); return wrapped ? (props) => (React.createElement("piral-component", { origin: outerProps.piral.meta.name }, React.createElement(Wrapper, { ...props }))) : Wrapper; } export function withApi(context, component, piral, errorType, wrapperType = errorType, captured = {}) { const outerProps = { ...captured, piral }; const converters = context.converters; const Wrapper = makeWrapper(context, outerProps, wrapperType, errorType); return wrapComponent(converters, component, outerProps, Wrapper); } //# sourceMappingURL=withApi.js.map