Skip to content

Commit 7e5a919

Browse files
committed
fix: fixed the issue that thisRequiredInJSE did not take effect in some scenarios
1 parent b216aa5 commit 7e5a919

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

packages/renderer-core/src/hoc/leaf.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
141141
__debug,
142142
__getComponentProps: getProps,
143143
__getSchemaChildrenVirtualDom: getChildren,
144+
__parseData,
144145
} = baseRenderer;
145146
const { engine } = baseRenderer.context;
146147
const host = baseRenderer.props?.__host;
@@ -225,7 +226,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
225226
nodeChildren: null,
226227
childrenInState: false,
227228
visible: !hidden,
228-
condition: parseData(condition, scope),
229+
condition: __parseData(condition, scope),
229230
nodeCacheProps: {},
230231
nodeProps: {},
231232
};
@@ -395,7 +396,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
395396

396397
if (key === '___condition___') {
397398
const { condition = true } = this.leaf?.export(TransformStage.Render) || {};
398-
const conditionValue = parseData(condition, scope);
399+
const conditionValue = __parseData(condition, scope);
399400
__debug(`key is ___condition___, change condition value to [${condition}]`);
400401
// 条件表达式改变
401402
this.setState({

packages/renderer-core/src/renderer/base.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ export default function baseRendererFactory(): IBaseRenderComponent {
245245
};
246246

247247
__parseData = (data: any, ctx?: Record<string, any>) => {
248-
const { __ctx } = this.props;
249-
return parseData(data, ctx || __ctx || this);
248+
const { __ctx, thisRequiredInJSE } = this.props;
249+
return parseData(data, ctx || __ctx || this, { thisRequiredInJSE });
250250
};
251251

252252
__initDataSource = (props = this.props) => {
@@ -479,7 +479,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
479479
const displayInHook = engine?.props?.designMode === 'design';
480480

481481
if (schema.loop != null) {
482-
const loop = parseData(schema.loop, scope);
482+
const loop = this.__parseData(schema.loop, scope);
483483
const useLoop = isUseLoop(loop, this._designModeIsDesign);
484484
if (useLoop) {
485485
return this.__createLoopVirtualDom(
@@ -493,7 +493,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
493493
);
494494
}
495495
}
496-
const condition = schema.condition == null ? true : parseData(schema.condition, scope);
496+
const condition = schema.condition == null ? true : this.__parseData(schema.condition, scope);
497497
if (!condition && !displayInHook) return null;
498498

499499
let scopeKey = '';

packages/renderer-core/src/renderer/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import baseRendererFactory from './base';
2-
import { parseData } from '../utils';
32
import { IBaseRendererProps, IBaseRenderComponent } from '../types';
43

54
export default function pageRendererFactory(): IBaseRenderComponent {
@@ -21,8 +20,8 @@ export default function pageRendererFactory(): IBaseRenderComponent {
2120

2221
async componentDidUpdate(prevProps: IBaseRendererProps, _prevState: {}, snapshot: unknown) {
2322
const { __ctx } = this.props;
24-
const prevState = parseData(prevProps.__schema.state, __ctx);
25-
const newState = parseData(this.props.__schema.state, __ctx);
23+
const prevState = this.__parseData(prevProps.__schema.state, __ctx);
24+
const newState = this.__parseData(this.props.__schema.state, __ctx);
2625
// 当编排的时候修改schema.state值,需要将最新schema.state值setState
2726
if (JSON.stringify(newState) != JSON.stringify(prevState)) {
2827
this.setState(newState);

packages/renderer-core/src/utils/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,15 @@ export function forEach(targetObj: any, fn: any, context?: any) {
330330
Object.keys(targetObj).forEach((key) => fn.call(context, targetObj[key], key));
331331
}
332332

333-
export function parseData(schema: unknown, self: any): any {
333+
export function parseData(schema: unknown, self: any, options: any): any {
334334
if (isJSExpression(schema)) {
335-
return parseExpression(schema, self);
335+
return parseExpression(schema, self, options.thisRequiredInJSE);
336336
} else if (isI18nData(schema)) {
337337
return parseI18n(schema, self);
338338
} else if (typeof schema === 'string') {
339339
return schema.trim();
340340
} else if (Array.isArray(schema)) {
341-
return schema.map((item) => parseData(item, self));
341+
return schema.map((item) => parseData(item, self, options));
342342
} else if (typeof schema === 'function') {
343343
return schema.bind(self);
344344
} else if (typeof schema === 'object') {
@@ -351,7 +351,7 @@ export function parseData(schema: unknown, self: any): any {
351351
if (key.startsWith('__')) {
352352
return;
353353
}
354-
res[key] = parseData(val, self);
354+
res[key] = parseData(val, self, options);
355355
});
356356
return res;
357357
}

0 commit comments

Comments
 (0)