UNPKG

@ray-core/runtime

Version:

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

68 lines (67 loc) 3.26 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { setPrototypeTo, gStore } from './gStore'; /** * 重载原生小程序的 `Component` 构造函数 */ export function overloadNativeComponentConstructor(name) { return function (cfg) { var config = {}; // 兼容阿里 if (process.env.REMAX_PLATFORM === 'ali') { var didMount_1 = cfg.didMount; var didUnmount_1 = cfg.didUnmount; var onInit_1 = cfg.onInit; var deriveDataFromProps_1 = cfg.deriveDataFromProps; config = __assign(__assign({}, cfg), { didMount: function () { didMount_1 === null || didMount_1 === void 0 ? void 0 : didMount_1.apply(this, arguments); }, didUnmount: function () { didUnmount_1 === null || didUnmount_1 === void 0 ? void 0 : didUnmount_1.apply(this, arguments); }, onInit: function () { this.componentName = name; setPrototypeTo(this); onInit_1 === null || onInit_1 === void 0 ? void 0 : onInit_1.apply(this, arguments); }, deriveDataFromProps: function (props) { this.setData(__assign({}, props.__p__)); deriveDataFromProps_1 === null || deriveDataFromProps_1 === void 0 ? void 0 : deriveDataFromProps_1(props); } }); } else { // 其他平台小程序 var properties = __assign(__assign({}, cfg.properties), { __instid__: { type: null, value: null } }); if (!properties.__p__) { properties.__p__ = { type: null, value: null }; } var observers = __assign({}, cfg.observers); if (!(observers === null || observers === void 0 ? void 0 : observers.__p__)) { observers.__p__ = function (props) { var k = "$_cb_".concat(this.data.__instid__, "___p__.onInput"); var cb = gStore.getCallback(k); this[k] = cb; Object.keys(props).length > 0 && this.setData(__assign({}, props)); }; } var lifetimes = __assign({}, cfg.lifetimes); var created_1 = cfg.created || lifetimes.created; lifetimes.created = function () { this.componentName = name; setPrototypeTo(this); created_1 === null || created_1 === void 0 ? void 0 : created_1.apply(this, arguments); }; config = __assign(__assign({}, cfg), { properties: properties, observers: observers, options: __assign(__assign({}, cfg.options), { styleIsolation: 'apply-shared', multipleSlots: true }) }); config.lifetimes = lifetimes; config = __assign(__assign({}, config), lifetimes); } // @ts-ignore Component(config); }; }