()
| 3 | import baseRendererFactory from './base'; |
| 4 | |
| 5 | export default function tempRendererFactory(): IBaseRenderComponent { |
| 6 | const BaseRenderer = baseRendererFactory(); |
| 7 | |
| 8 | return class TempRenderer extends BaseRenderer { |
| 9 | static displayName = 'TempRenderer'; |
| 10 | |
| 11 | __namespace = 'temp'; |
| 12 | |
| 13 | cacheSetState?: Record<string, any>; |
| 14 | |
| 15 | __init() { |
| 16 | this.state = {}; |
| 17 | this.cacheSetState = {}; |
| 18 | } |
| 19 | |
| 20 | async componentDidMount() { |
| 21 | const ctx = this.props.__ctx; |
| 22 | if (!ctx) return; |
| 23 | const { setState } = ctx; |
| 24 | this.cacheSetState = setState; |
| 25 | ctx.setState = (...args: any) => { |
| 26 | setState.call(ctx, ...args); |
| 27 | setTimeout(() => this.forceUpdate(), 0); |
| 28 | }; |
| 29 | this.__debug(`componentDidMount - ${this.props.__schema.fileName}`); |
| 30 | } |
| 31 | |
| 32 | async componentDidUpdate() { |
| 33 | this.__debug(`componentDidUpdate - ${this.props.__schema.fileName}`); |
| 34 | } |
| 35 | |
| 36 | async componentWillUnmount() { |
| 37 | const ctx = this.props.__ctx; |
| 38 | if (!ctx || !this.cacheSetState) return; |
| 39 | ctx.setState = this.cacheSetState; |
| 40 | delete this.cacheSetState; |
| 41 | this.__debug(`componentWillUnmount - ${this.props.__schema.fileName}`); |
| 42 | } |
| 43 | |
| 44 | async componentDidCatch(e: any) { |
| 45 | logger.warn(e); |
| 46 | this.__debug(`componentDidCatch - ${this.props.__schema.fileName}`); |
| 47 | } |
| 48 | |
| 49 | render() { |
| 50 | const { __schema, __ctx } = this.props; |
| 51 | if (this.__checkSchema(__schema)) { |
| 52 | return '下钻编辑 schema 结构异常!'; |
| 53 | } |
| 54 | |
| 55 | this.__debug(`${TempRenderer.displayName} render - ${__schema?.fileName}`); |
| 56 | |
| 57 | return this.__renderContent(this.__renderContextProvider({ __ctx })); |
| 58 | } |
| 59 | }; |
| 60 | } |
no test coverage detected
searching dependent graphs…