Skip to content

Commit 962be6a

Browse files
committed
clone object in combine method
1 parent f591400 commit 962be6a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/base/utils.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export function hasRepeat(list) {
9292
// ----------------- schema 相关
9393

9494
// 合并propsSchema和UISchema。由于两者的逻辑相关性,合并为一个大schema能简化内部处理
95-
export function combineSchema(propsSchema, uiSchema) {
95+
export function combineSchema(_propsSchema, _uiSchema) {
96+
const propsSchema = clone(_propsSchema);
97+
const uiSchema = clone(_uiSchema);
9698
const propList = getChildren(propsSchema);
9799
const newList = propList.map(p => {
98100
const { name } = p;
@@ -212,6 +214,7 @@ export function isFunction(func) {
212214
}
213215

214216
// 判断schema中是否有属性值是函数表达式
217+
// TODO: 这个util,没有考虑schema是array的情况,不过目前没有被用到
215218
export function isFunctionSchema(schema) {
216219
return Object.keys(schema).some(key => {
217220
if (typeof schema[key] === 'function') {
@@ -295,3 +298,26 @@ function isKey(value, object) {
295298
(object != null && value in Object(object))
296299
);
297300
}
301+
302+
// 将schema内所有的 {{ ... }} 转换为正常函数,我们试着一次性在外部做好这件事,而不是在内部每次去计算,优化性能
303+
304+
export function funcfySchema(schema) {
305+
let _schema = clone(schema);
306+
if (isObj(_schema)) {
307+
Object.keys(_schema).forEach(key => {
308+
_schema[key] = funcfySchema(_schema[key]);
309+
});
310+
} else if (Array.isArray(_schema)) {
311+
_schema = _schema.map(item => funcfySchema(item));
312+
} else {
313+
const funcBody = isFunction(schema);
314+
if (typeof funcBody === 'string') {
315+
try {
316+
_schema = new Function('formData', 'rootValue', `return ${funcBody}`);
317+
} catch (error) {
318+
console.error('funcfySchema', error);
319+
}
320+
}
321+
}
322+
return _schema;
323+
}

0 commit comments

Comments
 (0)