UNPKG

@remax/framework-shared

Version:

使用真正的 React 构建跨平台小程序

68 lines (67 loc) 3.33 kB
var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import PluginDriver from './PluginDriver'; var defaultRuntimeOptions = { pxToRpx: true, hostComponents: {}, debug: false, appEvents: [], pageEvents: {}, pluginDriver: new PluginDriver([]), history: {}, mpa: false, }; var runtimeOptions = defaultRuntimeOptions; function merge() { var options = []; for (var _i = 0; _i < arguments.length; _i++) { options[_i] = arguments[_i]; } return options.reduce(function (acc, option) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; acc.appEvents = (_a = option.appEvents) !== null && _a !== void 0 ? _a : acc.appEvents; acc.debug = (_b = option.debug) !== null && _b !== void 0 ? _b : acc.debug; acc.history = (_c = option.history) !== null && _c !== void 0 ? _c : acc.history; Object.keys((_d = option.hostComponents) !== null && _d !== void 0 ? _d : {}).forEach(function (k) { var _a, _b, _c, _d, _e, _f, _g; var inputHostComponent = (_a = option.hostComponents) === null || _a === void 0 ? void 0 : _a[k]; acc.hostComponents[k] = (_b = acc.hostComponents[k]) !== null && _b !== void 0 ? _b : {}; acc.hostComponents[k].additional = (_c = inputHostComponent === null || inputHostComponent === void 0 ? void 0 : inputHostComponent.additional) !== null && _c !== void 0 ? _c : acc.hostComponents[k].additional; acc.hostComponents[k].alias = Object.assign((_d = acc.hostComponents[k].alias) !== null && _d !== void 0 ? _d : {}, (_e = inputHostComponent === null || inputHostComponent === void 0 ? void 0 : inputHostComponent.alias) !== null && _e !== void 0 ? _e : {}); acc.hostComponents[k].props = __spread(new Set(__spread(((_f = acc.hostComponents[k].props) !== null && _f !== void 0 ? _f : []), ((_g = inputHostComponent === null || inputHostComponent === void 0 ? void 0 : inputHostComponent.props) !== null && _g !== void 0 ? _g : [])))); }); acc.pluginDriver = (_e = option.pluginDriver) !== null && _e !== void 0 ? _e : acc.pluginDriver; acc.pageEvents = (_f = option.pageEvents) !== null && _f !== void 0 ? _f : acc.pageEvents; acc.platform = (_g = option.platform) !== null && _g !== void 0 ? _g : acc.platform; acc.pxToRpx = (_h = option.pxToRpx) !== null && _h !== void 0 ? _h : acc.pxToRpx; acc.mpa = (_j = option.mpa) !== null && _j !== void 0 ? _j : acc.mpa; return acc; }, runtimeOptions); } export function apply(options) { runtimeOptions = merge(options); } export function get(key) { return runtimeOptions[key]; } export function reset() { runtimeOptions = defaultRuntimeOptions; }