60 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import baseRendererFactory from './base';
import { IBaseRendererProps, IBaseRenderComponent } from '../types';
export default function pageRendererFactory(): IBaseRenderComponent {
const BaseRenderer = baseRendererFactory();
return class PageRenderer extends BaseRenderer {
static dislayName = 'page-renderer';
__namespace = 'page';
__afterInit(props: IBaseRendererProps, ...rest: unknown[]) {
this.__generateCtx({
page: this,
});
const schema = props.__schema || {};
this.state = this.__parseData(schema.state || {});
this.__initDataSource(props);
this.__excuteLifeCycleMethod('constructor', [props, ...rest]);
}
async componentDidUpdate(prevProps: IBaseRendererProps, _prevState: {}, snapshot: unknown) {
const { __ctx } = this.props;
const prevState = this.__parseData(prevProps.__schema.state, __ctx);
const newState = this.__parseData(this.props.__schema.state, __ctx);
// 当编排的时候修改schema.state值需要将最新schema.state值setState
if (JSON.stringify(newState) != JSON.stringify(prevState)) {
this.setState(newState);
}
super.componentDidUpdate?.(prevProps, _prevState, snapshot);
}
render() {
const { __schema, __components } = this.props;
if (this.__checkSchema(__schema)) {
return '页面schema结构异常';
}
this.__debug(`${PageRenderer.dislayName} render - ${__schema.fileName}`);
this.__bindCustomMethods(this.props);
this.__initDataSource(this.props);
// this.__excuteLifeCycleMethod('constructor', arguments);
this.__generateCtx({
page: this,
});
this.__render();
const { Page } = __components;
if (Page) {
return this.__renderComp(Page, { pageContext: this });
}
return this.__renderContent(this.__renderContextProvider({ pageContext: this }));
}
};
}