UNPKG

@tamagui/react-native-web-lite

Version:
66 lines (65 loc) 3.07 kB
import { unmountComponentAtNode } from "react-dom"; import { invariant } from "@tamagui/react-native-web-internals"; import { renderApplication, getApplication } from "./renderApplication.mjs"; const emptyObject = {}, runnables = {}; let componentProviderInstrumentationHook = component => component(), wrapperComponentProvider; class AppRegistry { static getAppKeys() { return Object.keys(runnables); } static getApplication(appKey, appParameters) { return invariant(runnables[appKey] && runnables[appKey].getApplication, `Application ${appKey} has not been registered. This is either due to an import error during initialization or failure to call AppRegistry.registerComponent.`), runnables[appKey]?.getApplication?.(appParameters); } static registerComponent(appKey, componentProvider) { return runnables[appKey] = { getApplication: appParameters => getApplication(componentProviderInstrumentationHook(componentProvider), appParameters ? appParameters.initialProps : emptyObject, wrapperComponentProvider && wrapperComponentProvider(appParameters)), run: appParameters => renderApplication(componentProviderInstrumentationHook(componentProvider), wrapperComponentProvider && wrapperComponentProvider(appParameters), appParameters.callback, { hydrate: appParameters.hydrate || !1, initialProps: appParameters.initialProps || emptyObject, mode: appParameters.mode || "legacy", rootTag: appParameters.rootTag }) }, appKey; } static registerConfig(config) { config.forEach(({ appKey, component, run }) => { run ? AppRegistry.registerRunnable(appKey, run) : (invariant(component, "No component provider passed in"), AppRegistry.registerComponent(appKey, component)); }); } // TODO: fix style sheet creation when using this method static registerRunnable(appKey, run) { return runnables[appKey] = { run }, appKey; } static runApplication(appKey, appParameters) { const isDevelopment = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test"; if (isDevelopment) { const params = { ...appParameters }; params.rootTag = `#${params.rootTag.id}`, console.log(`Running application "${appKey}" with appParams: `, params, ` Development-level warnings: ${isDevelopment ? "ON" : "OFF"}. Performance optimizations: ${isDevelopment ? "OFF" : "ON"}.`); } return invariant(runnables[appKey] && runnables[appKey].run, `Application "${appKey}" has not been registered. This is either due to an import error during initialization or failure to call AppRegistry.registerComponent.`), runnables[appKey].run(appParameters); } static setComponentProviderInstrumentationHook(hook) { componentProviderInstrumentationHook = hook; } static setWrapperComponentProvider(provider) { wrapperComponentProvider = provider; } static unmountApplicationComponentAtRootTag(rootTag) { unmountComponentAtNode(rootTag); } } export { AppRegistry }; //# sourceMappingURL=index.mjs.map