From a33a91a0914adc2c3ae95bcb7765cd9e6b82fe8c Mon Sep 17 00:00:00 2001 From: gchust Date: Mon, 30 Jun 2025 18:35:32 +0800 Subject: [PATCH] chore: remove props from model options --- .../src/models/__tests__/flowModel.test.ts | 55 +++---------------- .../core/flow-engine/src/models/flowModel.tsx | 2 +- packages/core/flow-engine/src/types.ts | 1 - 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/packages/core/flow-engine/src/models/__tests__/flowModel.test.ts b/packages/core/flow-engine/src/models/__tests__/flowModel.test.ts index ad23a56aea..a1ac985c90 100644 --- a/packages/core/flow-engine/src/models/__tests__/flowModel.test.ts +++ b/packages/core/flow-engine/src/models/__tests__/flowModel.test.ts @@ -135,7 +135,6 @@ beforeEach(() => { modelOptions = { uid: 'test-model-uid', flowEngine, - props: { testProp: 'value' }, stepParams: { testFlow: { step1: { param1: 'value1' } } }, sortIndex: 0, subModels: {}, @@ -150,7 +149,6 @@ describe('FlowModel', () => { const model = new FlowModel(modelOptions); expect(model.uid).toBe(modelOptions.uid); - expect(model.props).toEqual(expect.objectContaining(modelOptions.props)); expect(model.stepParams).toEqual(expect.objectContaining(modelOptions.stepParams)); expect(model.flowEngine).toBe(modelOptions.flowEngine); expect(model.sortIndex).toBe(modelOptions.sortIndex); @@ -682,7 +680,6 @@ describe('FlowModel', () => { const childModel = new FlowModel({ uid: 'child-model-uid', flowEngine, - props: { childProp: 'childValue' }, stepParams: { childFlow: { childStep: { childParam: 'childValue' } } }, }); @@ -692,12 +689,11 @@ describe('FlowModel', () => { expect(result.parent).toBe(parentModel); expect((parentModel.subModels.testChild as FlowModel).uid).toBe(result.uid); expect(result.uid).toBe('child-model-uid'); - expect(result.props).toEqual(expect.objectContaining({ childProp: 'childValue' })); }); test('should replace existing subModel', () => { const firstChild = new FlowModel({ uid: 'first-child', flowEngine }); - const secondChild = new FlowModel({ uid: 'second-child', flowEngine, props: { newProp: 'newValue' } }); + const secondChild = new FlowModel({ uid: 'second-child', flowEngine }); parentModel.setSubModel('testChild', firstChild); const result = parentModel.setSubModel('testChild', secondChild); @@ -705,7 +701,6 @@ describe('FlowModel', () => { expect(result.uid).toBe(secondChild.uid); expect((parentModel.subModels.testChild as FlowModel).uid).toBe(result.uid); expect(result.uid).toBe('second-child'); - expect(result.props).toEqual(expect.objectContaining({ newProp: 'newValue' })); }); test('should throw error when setting model with existing parent', () => { @@ -734,7 +729,6 @@ describe('FlowModel', () => { const childModel = new FlowModel({ uid: 'child-model-uid', flowEngine, - props: { childProp: 'childValue' }, }); const result = parentModel.addSubModel('testChildren', childModel); @@ -830,53 +824,35 @@ describe('FlowModel', () => { expect(results).toEqual([]); }); - - test('should handle complex mapping operations', () => { - const item1 = new FlowModel({ uid: 'item1', flowEngine, props: { value: 10 } }); - const item2 = new FlowModel({ uid: 'item2', flowEngine, props: { value: 20 } }); - - parentModel.addSubModel('items', item1); - parentModel.addSubModel('items', item2); - - const totalValue = parentModel - .mapSubModels('items', (model) => model.props.value) - .reduce((sum, value) => sum + value, 0); - - expect(totalValue).toBe(30); - }); }); describe('findSubModel', () => { test('should find subModel by condition in array', () => { - const child1 = new FlowModel({ uid: 'child1', flowEngine, props: { name: 'first' } }); - const child2 = new FlowModel({ uid: 'child2', flowEngine, props: { name: 'second' } }); + const child1 = new FlowModel({ uid: 'child1', flowEngine }); + const child2 = new FlowModel({ uid: 'child2', flowEngine }); parentModel.addSubModel('testChildren', child1); parentModel.addSubModel('testChildren', child2); - const found = parentModel.findSubModel('testChildren', (model) => model.props.name === 'second'); + const found = parentModel.findSubModel('testChildren', (model) => model.uid === 'child2'); expect(found).toBeDefined(); - expect(found?.uid).toBe('child2'); - expect(found?.props.name).toBe('second'); }); test('should find single subModel by condition', () => { - const child = new FlowModel({ uid: 'target-child', flowEngine, props: { name: 'target' } }); + const child = new FlowModel({ uid: 'target-child', flowEngine }); parentModel.setSubModel('testChild', child); - const found = parentModel.findSubModel('testChild', (model) => model.props.name === 'target'); + const found = parentModel.findSubModel('testChild', (model) => model.uid === 'target-child'); expect(found).toBeDefined(); - expect(found?.uid).toBe('target-child'); - expect(found?.props.name).toBe('target'); }); test('should return null when no match found', () => { - const child1 = new FlowModel({ uid: 'child1', flowEngine, props: { name: 'first' } }); + const child1 = new FlowModel({ uid: 'child1', flowEngine }); parentModel.addSubModel('testChildren', child1); - const found = parentModel.findSubModel('testChildren', (model) => model.props.name === 'nonexistent'); + const found = parentModel.findSubModel('testChildren', (model) => model.uid === 'nonexistent'); expect(found).toBeNull(); }); @@ -886,20 +862,6 @@ describe('FlowModel', () => { expect(found).toBeNull(); }); - - test('should find first matching model in array', () => { - const child1 = new FlowModel({ uid: 'child1', flowEngine, props: { type: 'match' } }); - const child2 = new FlowModel({ uid: 'child2', flowEngine, props: { type: 'match' } }); - - parentModel.addSubModel('testChildren', child1); - parentModel.addSubModel('testChildren', child2); - - const found = parentModel.findSubModel('testChildren', (model) => model.props.type === 'match'); - - expect(found).toBeDefined(); - expect(found?.uid).toBe('child1'); // Should return first match - expect(found?.props.type).toBe('match'); - }); }); describe('applySubModelsAutoFlows', () => { @@ -1245,7 +1207,6 @@ describe('FlowModel', () => { const emptyModel = new FlowModel({ uid: 'empty-model', flowEngine, - props: {}, stepParams: {}, subModels: {}, }); diff --git a/packages/core/flow-engine/src/models/flowModel.tsx b/packages/core/flow-engine/src/models/flowModel.tsx index a280dfc26a..0137b58960 100644 --- a/packages/core/flow-engine/src/models/flowModel.tsx +++ b/packages/core/flow-engine/src/models/flowModel.tsx @@ -87,7 +87,7 @@ export class FlowModel { } this.uid = options.uid; - this.props = options.props || {}; + this.props = {}; this.stepParams = options.stepParams || {}; this.subModels = {}; this.sortIndex = options.sortIndex || 0; diff --git a/packages/core/flow-engine/src/types.ts b/packages/core/flow-engine/src/types.ts index eb91868d56..f732200f87 100644 --- a/packages/core/flow-engine/src/types.ts +++ b/packages/core/flow-engine/src/types.ts @@ -315,7 +315,6 @@ export interface FlowModelOptions