From aa185d96e7e92af7e5b76b15b384020792feb13d Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 27 Dec 2019 11:08:20 +0800 Subject: [PATCH] clear memoized cache --- src/renderers/Form/Combo.tsx | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/renderers/Form/Combo.tsx b/src/renderers/Form/Combo.tsx index e0b14d85..b0bfb1cc 100644 --- a/src/renderers/Form/Combo.tsx +++ b/src/renderers/Form/Combo.tsx @@ -22,18 +22,6 @@ import {dataMapping} from '../../utils/tpl-builtin'; import {isEffectiveApi} from '../../utils/api'; import {Alert2} from '../../components'; import memoize from 'lodash/memoize'; - -const formatValue = memoize( - (strictMode: boolean, value: any, index: number, data: any) => { - return createObject( - extendObject(data, {index, __index: index, ...data}), - value - ); - }, - (strictMode: boolean, ...args: Array) => - strictMode ? JSON.stringify(args.slice(0, 2)) : JSON.stringify(args) -); - export interface Condition { test: string; controls: Array; @@ -191,6 +179,8 @@ export default class ComboControl extends React.Component { this.toDispose.forEach(fn => fn()); this.toDispose = []; + this.memoizedFormatValue.cache.clear?.(); + this.makeFormRef.cache.clear?.(); } getValueAsArray(props = this.props) { @@ -543,6 +533,17 @@ export default class ComboControl extends React.Component { } } + memoizedFormatValue = memoize( + (strictMode: boolean, value: any, index: number, data: any) => { + return createObject( + extendObject(data, {index, __index: index, ...data}), + value + ); + }, + (strictMode: boolean, ...args: Array) => + strictMode ? JSON.stringify(args.slice(0, 2)) : JSON.stringify(args) + ); + formatValue(value: any, index: number) { const {flat, data, strictMode} = this.props; @@ -554,7 +555,7 @@ export default class ComboControl extends React.Component { value = value || this.defaultValue; - return formatValue(strictMode !== false, value, index, data); + return this.memoizedFormatValue(strictMode !== false, value, index, data); } pickCondition(value: any): Condition | null {