UNPKG

@tamagui/react-native-web-lite

Version:
111 lines (109 loc) 4.95 kB
import { unmountComponentAtNode } from "react-dom"; import { invariant } from "@tamagui/react-native-web-internals"; import renderApplication, { getApplication } from "./renderApplication.native.js"; function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } var emptyObject = {}, runnables = {}, componentProviderInstrumentationHook = function (component) { return component(); }, wrapperComponentProvider, AppRegistry = /* @__PURE__ */function () { "use strict"; function AppRegistry2() { _class_call_check(this, AppRegistry2); } return _create_class(AppRegistry2, null, [{ key: "getAppKeys", value: function () { return Object.keys(runnables); } }, { key: "getApplication", value: function (appKey, appParameters) { var _runnables_appKey_getApplication, _runnables_appKey; 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 = runnables[appKey]) === null || _runnables_appKey === void 0 || (_runnables_appKey_getApplication = _runnables_appKey.getApplication) === null || _runnables_appKey_getApplication === void 0 ? void 0 : _runnables_appKey_getApplication.call(_runnables_appKey, appParameters); } }, { key: "registerComponent", value: function (appKey, componentProvider) { return runnables[appKey] = { getApplication: function (appParameters) { return getApplication(componentProviderInstrumentationHook(componentProvider), appParameters ? appParameters.initialProps : emptyObject, wrapperComponentProvider && wrapperComponentProvider(appParameters)); }, run: function (appParameters) { return renderApplication(componentProviderInstrumentationHook(componentProvider), wrapperComponentProvider && wrapperComponentProvider(appParameters), appParameters.callback, { hydrate: appParameters.hydrate || !1, initialProps: appParameters.initialProps || emptyObject, mode: appParameters.mode || "legacy", rootTag: appParameters.rootTag }); } }, appKey; } }, { key: "registerConfig", value: function (config) { config.forEach(function (param) { var { appKey, component, run } = param; run ? AppRegistry2.registerRunnable(appKey, run) : (invariant(component, "No component provider passed in"), AppRegistry2.registerComponent(appKey, component)); }); } }, { key: "registerRunnable", value: // TODO: fix style sheet creation when using this method function (appKey, run) { return runnables[appKey] = { run }, appKey; } }, { key: "runApplication", value: function (appKey, appParameters) { var isDevelopment = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test"; if (isDevelopment) { var 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); } }, { key: "setComponentProviderInstrumentationHook", value: function (hook) { componentProviderInstrumentationHook = hook; } }, { key: "setWrapperComponentProvider", value: function (provider) { wrapperComponentProvider = provider; } }, { key: "unmountApplicationComponentAtRootTag", value: function (rootTag) { unmountComponentAtNode(rootTag); } }]), AppRegistry2; }(); export { AppRegistry as default }; //# sourceMappingURL=index.native.js.map