UNPKG

@alilc/lowcode-renderer-core

Version:
91 lines 3.8 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { getLogger } from '@alilc/lowcode-utils'; import baseRendererFactory from './base'; var logger = getLogger({ level: 'warn', bizName: 'renderer-core:page' }); export default function pageRendererFactory() { var _PageRenderer; var BaseRenderer = baseRendererFactory(); return _PageRenderer = /*#__PURE__*/function (_BaseRenderer) { function PageRenderer() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _BaseRenderer.call.apply(_BaseRenderer, [this].concat(args)) || this; _this.__namespace = 'page'; return _this; } _inheritsLoose(PageRenderer, _BaseRenderer); var _proto = PageRenderer.prototype; _proto.__afterInit = function __afterInit(props) { this.__generateCtx({ page: this }); var schema = props.__schema || {}; this.state = this.__parseData(schema.state || {}); this.__initDataSource(props); for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { rest[_key2 - 1] = arguments[_key2]; } this.__executeLifeCycleMethod('constructor', [props].concat(rest)); }; _proto.componentDidUpdate = /*#__PURE__*/function () { var _componentDidUpdate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(prevProps, _prevState, snapshot) { var _BaseRenderer$prototy; var __ctx, newState; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: __ctx = this.props.__ctx; // 当编排的时候修改 schema.state 值,需要将最新 schema.state 值 setState if (JSON.stringify(prevProps.__schema.state) != JSON.stringify(this.props.__schema.state)) { newState = this.__parseData(this.props.__schema.state, __ctx); this.setState(newState); } (_BaseRenderer$prototy = _BaseRenderer.prototype.componentDidUpdate) === null || _BaseRenderer$prototy === void 0 ? void 0 : _BaseRenderer$prototy.call(this, prevProps, _prevState, snapshot); case 3: case "end": return _context.stop(); } }, _callee, this); })); function componentDidUpdate(_x, _x2, _x3) { return _componentDidUpdate.apply(this, arguments); } return componentDidUpdate; }(); _proto.setState = function setState(state, callback) { logger.info('page set state', state); _BaseRenderer.prototype.setState.call(this, state, callback); }; _proto.render = function render() { var _this$props = this.props, __schema = _this$props.__schema, __components = _this$props.__components; if (this.__checkSchema(__schema)) { return '页面schema结构异常!'; } this.__debug(PageRenderer.displayName + " render - " + __schema.fileName); this.__bindCustomMethods(this.props); this.__initDataSource(this.props); this.__generateCtx({ page: this }); this.__render(); var Page = __components.Page; if (Page) { return this.__renderComp(Page, { pageContext: this }); } return this.__renderContent(this.__renderContextProvider({ pageContext: this })); }; return PageRenderer; }(BaseRenderer), _PageRenderer.displayName = 'PageRenderer', _PageRenderer; }