UNPKG

@morjs/runtime-web

Version:
89 lines 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Page = exports.Component = void 0; const tslib_1 = require("tslib"); const lodash_clonedeep_1 = tslib_1.__importDefault(require("lodash.clonedeep")); const component_1 = require("./component"); // import { MixinPageForHot } from './page-hot'; const component_mixin_1 = tslib_1.__importDefault(require("./component-mixin")); // import { MixinComponentForHot } from './component-hot' const page_1 = require("./page"); window.Component = function (options) { window.$$options$$ = options; }; const OWNER_PROPS_NAME = '$ownerId'; /** * 组件构造函数 * @param axmlInfo 初始化函数 */ function Component(axmlInfo) { return MixinComponent(axmlInfo); } exports.Component = Component; function cloneInitOptions(options) { try { const whiteList = ['$event']; const tempSaveObj = {}; whiteList.forEach((key) => { options[key] && (tempSaveObj[key] = options[key]); }); return Object.assign(Object.assign({}, (0, lodash_clonedeep_1.default)(options)), tempSaveObj); } catch (e) { } return (0, lodash_clonedeep_1.default)(options); } function MixinComponent(axmlInfo) { const componentInit = (0, component_mixin_1.default)(window.$$options$$ || {}); delete window.$$options$$; const { defaultRender: render, isComplexComponents } = axmlInfo; const componentData = componentInit.data; delete componentInit.data; return class extends component_1.KBComponent { constructor(props) { // data 的数据 对象可以共享。 这个是支付宝的逻辑,真是奇葩。 const cloneObj = cloneInitOptions(componentInit); cloneObj.data = Object.assign({}, componentData); super(props, cloneObj, { isComplexComponents, isComponent: true, ownerComponentId: axmlInfo[OWNER_PROPS_NAME] }); } render() { if (render) { return render.call(this.componentConfig, this.getRenderData()); } return false; } }; } function Page(axmlInfo, config) { return MixinPage(axmlInfo, config); } exports.Page = Page; window.Page = function (options) { window.$$options$$ = options; }; function MixinPage(axmlInfo, config) { const componentInit = window.$$options$$ || {}; delete window.$$options$$; const { defaultRender: render, isComplexComponents } = axmlInfo; return class extends page_1.PageComponent { constructor(props) { super(props, cloneInitOptions(componentInit), config, { isComplexComponents, ownerComponentId: axmlInfo[OWNER_PROPS_NAME] }); // 设置标题 window.document.title = config.window.defaultTitle || window.document.title || ''; } render() { if (render) { return render.call(this.componentConfig, this.getRenderData()); } return false; } }; } //# sourceMappingURL=index.js.map