UNPKG

@ray-core/runtime

Version:

Ray 是一个全新的基于 React 的小程序开发框架

51 lines (50 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bindBlendedAppInstance = exports.getNativeAppInstance = void 0; var resolve; var promise = new Promise(function (res, rej) { return (resolve = res); }); var _app; function getNativeAppInstance() { try { return getApp(); } catch (e) { } } exports.getNativeAppInstance = getNativeAppInstance; function bindBlendedAppInstance(inst) { resolve(inst); } exports.bindBlendedAppInstance = bindBlendedAppInstance; /** * 1. 用做主包 * 2. 用做子包 * 2.1. 独立子包 * 2.1.1. 通过主包打开 * 2.1.2. 直接打开 * 2.2. 普通子包(只能通过主包打开) */ function default_1() { if (_app) { return Promise.resolve(_app); } _app = getNativeAppInstance(); return promise.then(function (inst) { if (!inst) { // 用作主包 return _app; // 用作主包肯定有 app } // 用作独立子包 if (inst.asSubPackageRuntimeOptions.independent) { _app = inst; return inst; } // 用作普通子包 // 但未通过主包的 app.js 导入子包的 app.js // (因在主包的app.js 导入 子包的 app.js,会重载 App 构造函数,并在App 实例上挂 asSubPackageRuntimeOptions,以此可以判断) if (!_app.asSubPackageRuntimeOptions) { _app = inst; return inst; } return _app; }); } exports.default = default_1;