Skip to content

Commit 223460d

Browse files
feat: change connector ids to signals
1 parent 16dc995 commit 223460d

25 files changed

Lines changed: 462 additions & 320 deletions

File tree

projects/f-flow/src/domain/f-connection/redraw-connections/redraw-connections.execution.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FConnectorBase } from '../../../f-connectors';
77
import { FConnectionBase } from '../../../f-connection';
88
import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
99
import { CreateConnectionMarkersRequest } from '../create-connection-markers';
10-
import { GetNormalizedConnectorRectRequest } from "../../get-normalized-connector-rect";
10+
import { GetNormalizedConnectorRectRequest } from '../../get-normalized-connector-rect';
1111

1212
/**
1313
* Execution that redraws connections in the FComponentsStore.
@@ -17,11 +17,10 @@ import { GetNormalizedConnectorRectRequest } from "../../get-normalized-connecto
1717
@Injectable()
1818
@FExecutionRegister(RedrawConnectionsRequest)
1919
export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsRequest, void> {
20-
21-
private readonly _fMediator = inject(FMediator);
20+
private readonly _mediator = inject(FMediator);
2221
private readonly _store = inject(FComponentsStore);
2322

24-
public handle(request: RedrawConnectionsRequest): void {
23+
public handle(_request: RedrawConnectionsRequest): void {
2524
this._resetConnectors();
2625

2726
if (this._store.fTempConnection) {
@@ -38,7 +37,7 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
3837
}
3938

4039
private _getOutput(id: string): FConnectorBase {
41-
const result = this._store.fOutputs.find((x) => x.fId === id)!;
40+
const result = this._store.fOutputs.find((x) => x.fId() === id);
4241
if (!result) {
4342
throw new Error(`Output with id ${id} not found`);
4443
}
@@ -47,7 +46,7 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
4746
}
4847

4948
private _getInput(id: string): FConnectorBase {
50-
const result = this._store.fInputs.find((x) => x.fId === id)!;
49+
const result = this._store.fInputs.find((x) => x.fId() === id);
5150
if (!result) {
5251
throw new Error(`Input with id ${id} not found`);
5352
}
@@ -60,7 +59,11 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
6059
this._store.fInputs.forEach((x) => x.resetConnected());
6160
}
6261

63-
private _setupConnection(fOutput: FConnectorBase, fInput: FConnectorBase, fConnection: FConnectionBase): void {
62+
private _setupConnection(
63+
fOutput: FConnectorBase,
64+
fInput: FConnectorBase,
65+
fConnection: FConnectionBase,
66+
): void {
6467
fOutput.setConnected(fInput);
6568
fInput.setConnected(fOutput);
6669

@@ -74,10 +77,19 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
7477
fConnection.isSelected() ? fConnection.markAsSelected() : null;
7578
}
7679

77-
private _getLine(output: FConnectorBase, input: FConnectorBase, connection: FConnectionBase): ILine {
78-
return this._fMediator.execute(new CalculateConnectionLineByBehaviorRequest(
79-
this._fMediator.execute<IRoundedRect>(new GetNormalizedConnectorRectRequest(output.hostElement)),
80-
this._fMediator.execute<IRoundedRect>(new GetNormalizedConnectorRectRequest(input.hostElement)),
80+
private _getLine(
81+
output: FConnectorBase,
82+
input: FConnectorBase,
83+
connection: FConnectionBase,
84+
): ILine {
85+
return this._mediator.execute(
86+
new CalculateConnectionLineByBehaviorRequest(
87+
this._mediator.execute<IRoundedRect>(
88+
new GetNormalizedConnectorRectRequest(output.hostElement),
89+
),
90+
this._mediator.execute<IRoundedRect>(
91+
new GetNormalizedConnectorRectRequest(input.hostElement),
92+
),
8193
connection.fBehavior,
8294
output.fConnectableSide,
8395
input.fConnectableSide,
@@ -86,9 +98,6 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
8698
}
8799

88100
private _setMarkers(connection: FConnectionBase): void {
89-
this._fMediator.execute(
90-
new CreateConnectionMarkersRequest(connection),
91-
);
101+
this._mediator.execute(new CreateConnectionMarkersRequest(connection));
92102
}
93103
}
94-

projects/f-flow/src/domain/f-connectors/find-closest-connector/find-closest-connector.execution.spec.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,64 @@ import { FindClosestConnectorExecution } from '@foblex/flow';
77
import { FindClosestConnectorRequest } from '@foblex/flow';
88
import { FConnectorBase } from '@foblex/flow';
99
import { IClosestConnector } from '@foblex/flow';
10+
import { signal } from '@angular/core';
1011

1112
describe('FindClosestConnectorExecution', () => {
13+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1214
let fDraggableDataContext: FDraggableDataContext;
1315
let fMediator: FMediator;
1416

1517
beforeEach(() => {
16-
setupTestModule([ FindClosestConnectorExecution ]);
17-
fDraggableDataContext = TestBed.inject(FDraggableDataContext) as jasmine.SpyObj<FDraggableDataContext>;
18+
setupTestModule([FindClosestConnectorExecution]);
19+
fDraggableDataContext = TestBed.inject(
20+
FDraggableDataContext,
21+
) as jasmine.SpyObj<FDraggableDataContext>;
1822
fMediator = TestBed.inject(FMediator) as jasmine.SpyObj<FMediator>;
1923
});
2024

2125
it('should return undefined when connectors is empty', () => {
22-
const result = fMediator.execute(
23-
new FindClosestConnectorRequest({ x: 50, y: 50 }, []),
24-
);
26+
const result = fMediator.execute(new FindClosestConnectorRequest({ x: 50, y: 50 }, []));
2527
expect(result).toBeUndefined();
2628
});
2729

2830
it('should return the only element if its distance is less than snapThreshold', () => {
29-
3031
const result = fMediator.execute<IClosestConnector>(
31-
new FindClosestConnectorRequest({ x: 10, y: 10 }, [ {
32-
fConnector: {
33-
fId: 'input1',
34-
} as FConnectorBase,
35-
fRect: RoundedRect.fromRect(RectExtensions.initialize(12, 12, 10, 10)),
36-
}, {
37-
fConnector: {
38-
fId: 'input2',
39-
} as FConnectorBase,
40-
fRect: RoundedRect.fromRect(RectExtensions.initialize(22, 22, 10, 10)),
41-
} ]),
32+
new FindClosestConnectorRequest({ x: 10, y: 10 }, [
33+
{
34+
fConnector: {
35+
fId: signal('input1').asReadonly(),
36+
} as FConnectorBase,
37+
fRect: RoundedRect.fromRect(RectExtensions.initialize(12, 12, 10, 10)),
38+
},
39+
{
40+
fConnector: {
41+
fId: signal('input2').asReadonly(),
42+
} as FConnectorBase,
43+
fRect: RoundedRect.fromRect(RectExtensions.initialize(22, 22, 10, 10)),
44+
},
45+
]),
4246
);
4347
expect(result).toBeDefined();
44-
expect(result?.fConnector.fId).toBe('input1');
48+
expect(result?.fConnector.fId()).toBe('input1');
4549
});
4650

4751
it('should return 10 if the only element is exactly at snapThreshold distance', () => {
4852
const result = fMediator.execute<IClosestConnector>(
49-
new FindClosestConnectorRequest({ x: 0, y: 0 }, [ {
50-
fConnector: {
51-
fId: 'input1',
52-
} as FConnectorBase,
53-
fRect: RoundedRect.fromRect(RectExtensions.initialize(10, 0, 10, 10)),
54-
}, {
55-
fConnector: {
56-
fId: 'input2',
57-
} as FConnectorBase,
58-
fRect: RoundedRect.fromRect(RectExtensions.initialize(22, 22, 10, 10)),
59-
} ]),
53+
new FindClosestConnectorRequest({ x: 0, y: 0 }, [
54+
{
55+
fConnector: {
56+
fId: signal('input1').asReadonly(),
57+
} as FConnectorBase,
58+
fRect: RoundedRect.fromRect(RectExtensions.initialize(10, 0, 10, 10)),
59+
},
60+
{
61+
fConnector: {
62+
fId: signal('input2').asReadonly(),
63+
} as FConnectorBase,
64+
fRect: RoundedRect.fromRect(RectExtensions.initialize(22, 22, 10, 10)),
65+
},
66+
]),
6067
);
6168
expect(result?.distance).toBe(10);
6269
});
6370
});
64-
65-

projects/f-flow/src/domain/f-connectors/get-all-can-be-connected-inputs-and-rects/get-all-can-be-connected-inputs-and-rects.execution.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { GetConnectorAndRectRequest } from '../get-connector-and-rect';
1212
@Injectable()
1313
@FExecutionRegister(GetAllCanBeConnectedInputsAndRectsRequest)
1414
export class GetAllCanBeConnectedInputsAndRectsExecution
15-
implements IExecution<GetAllCanBeConnectedInputsAndRectsRequest, IConnectorAndRect[]> {
16-
15+
implements IExecution<GetAllCanBeConnectedInputsAndRectsRequest, IConnectorAndRect[]>
16+
{
1717
private readonly _mediator = inject(FMediator);
1818
private _store = inject(FComponentsStore);
1919

@@ -27,22 +27,27 @@ export class GetAllCanBeConnectedInputsAndRectsExecution
2727
});
2828
}
2929

30-
private _getCanBeConnectedInputs(fOutputOrOutlet: FNodeOutputBase | FNodeOutletBase): FConnectorBase[] {
30+
private _getCanBeConnectedInputs(
31+
fOutputOrOutlet: FNodeOutputBase | FNodeOutletBase,
32+
): FConnectorBase[] {
3133
let fInputs: FConnectorBase[] = [];
3234
if (fOutputOrOutlet.canBeConnectedInputs?.length) {
33-
fInputs = this._fInputs.filter((x) => fOutputOrOutlet.canBeConnectedInputs.includes(x.fId));
35+
fInputs = this._fInputs.filter((x) => fOutputOrOutlet.canBeConnectedInputs.includes(x.fId()));
3436
} else {
3537
fInputs = this._fInputs.filter((x) => x.canBeConnected);
3638

37-
if(!fOutputOrOutlet.isSelfConnectable) {
39+
if (!fOutputOrOutlet.isSelfConnectable) {
3840
fInputs = this._filterSelfConnectable(fInputs, fOutputOrOutlet);
3941
}
4042
}
4143

4244
return fInputs;
4345
}
4446

45-
private _filterSelfConnectable(fInputs: FConnectorBase[], fOutputOrOutlet: FConnectorBase): FConnectorBase[] {
47+
private _filterSelfConnectable(
48+
fInputs: FConnectorBase[],
49+
fOutputOrOutlet: FConnectorBase,
50+
): FConnectorBase[] {
4651
return fInputs.filter((x) => fOutputOrOutlet.fNodeId !== x.fNodeId);
4752
}
4853
}

projects/f-flow/src/domain/f-connectors/get-all-can-be-connected-source-connectors-and-rects/get-all-can-be-connected-source-connectors-and-rects.execution.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
GetAllCanBeConnectedSourceConnectorsAndRectsRequest,
3-
} from './get-all-can-be-connected-source-connectors-and-rects.request';
1+
import { GetAllCanBeConnectedSourceConnectorsAndRectsRequest } from './get-all-can-be-connected-source-connectors-and-rects.request';
42
import { inject, Injectable } from '@angular/core';
53
import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
64
import { FConnectorBase, FNodeInputBase, FNodeOutputBase } from '../../../f-connectors';
@@ -16,8 +14,8 @@ import { GetConnectorAndRectRequest } from '../get-connector-and-rect';
1614
@Injectable()
1715
@FExecutionRegister(GetAllCanBeConnectedSourceConnectorsAndRectsRequest)
1816
export class GetAllCanBeConnectedSourceConnectorsAndRectsExecution
19-
implements IExecution<GetAllCanBeConnectedSourceConnectorsAndRectsRequest, IConnectorAndRect[]> {
20-
17+
implements IExecution<GetAllCanBeConnectedSourceConnectorsAndRectsRequest, IConnectorAndRect[]>
18+
{
2119
private readonly _mediator = inject(FMediator);
2220
private readonly _store = inject(FComponentsStore);
2321

@@ -35,7 +33,7 @@ export class GetAllCanBeConnectedSourceConnectorsAndRectsExecution
3533
return this._fSourceConnectors.filter((x) => {
3634
let result = x.canBeConnected;
3735
if (result && x.canBeConnectedInputs?.length) {
38-
result = x.canBeConnectedInputs?.includes(fTargetConnector.fId);
36+
result = x.canBeConnectedInputs?.includes(fTargetConnector.fId());
3937
}
4038

4139
return result;

projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,47 @@ import { IFFlowStateConnector } from '../i-f-flow-state-connector';
1010
*/
1111
@Injectable()
1212
@FExecutionRegister(GetFlowStateNodesRequest)
13-
export class GetFlowStateNodesExecution implements IExecution<GetFlowStateNodesRequest, IFFlowStateNode[]> {
14-
13+
export class GetFlowStateNodesExecution
14+
implements IExecution<GetFlowStateNodesRequest, IFFlowStateNode[]>
15+
{
1516
private readonly _store = inject(FComponentsStore);
1617

1718
public handle(request: GetFlowStateNodesRequest): IFFlowStateNode[] {
18-
return this._store.fNodes.filter((x) => x instanceof request.type).map((x) => {
19-
return {
20-
id: x.fId(),
21-
parent: x.fParentId(),
22-
position: x._position,
23-
size: x._size,
24-
rotate: x._rotate,
25-
fOutputs: this._getOutputs(x.hostElement),
26-
fInputs: this._getInputs(x.hostElement),
27-
isSelected: x.isSelected(),
28-
};
29-
});
19+
return this._store.fNodes
20+
.filter((x) => x instanceof request.type)
21+
.map((x) => {
22+
return {
23+
id: x.fId(),
24+
parent: x.fParentId(),
25+
position: x._position,
26+
size: x._size,
27+
rotate: x._rotate,
28+
fOutputs: this._getOutputs(x.hostElement),
29+
fInputs: this._getInputs(x.hostElement),
30+
isSelected: x.isSelected(),
31+
};
32+
});
3033
}
3134

3235
private _getOutputs(hostElement: HTMLElement): IFFlowStateConnector[] {
33-
return this._store.fOutputs.filter((x) => hostElement.contains(x.hostElement)).map((x) => {
34-
return {
35-
id: x.fId,
36-
fConnectableSide: x.fConnectableSide,
37-
}
38-
});
36+
return this._store.fOutputs
37+
.filter((x) => hostElement.contains(x.hostElement))
38+
.map((x) => {
39+
return {
40+
id: x.fId(),
41+
fConnectableSide: x.fConnectableSide,
42+
};
43+
});
3944
}
4045

4146
private _getInputs(hostElement: HTMLElement): IFFlowStateConnector[] {
42-
return this._store.fInputs.filter((x) => hostElement.contains(x.hostElement)).map((x) => {
43-
return {
44-
id: x.fId,
45-
fConnectableSide: x.fConnectableSide,
46-
}
47-
});
47+
return this._store.fInputs
48+
.filter((x) => hostElement.contains(x.hostElement))
49+
.map((x) => {
50+
return {
51+
id: x.fId(),
52+
fConnectableSide: x.fConnectableSide,
53+
};
54+
});
4855
}
4956
}

projects/f-flow/src/domain/f-node/calculate-input-connections/calculate-input-connections.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ import { FConnectionBase } from '../../../f-connection';
1010
*/
1111
@Injectable()
1212
@FExecutionRegister(CalculateInputConnectionsRequest)
13-
export class CalculateInputConnections implements IExecution<CalculateInputConnectionsRequest, FConnectionBase[]> {
14-
13+
export class CalculateInputConnections
14+
implements IExecution<CalculateInputConnectionsRequest, FConnectionBase[]>
15+
{
1516
private readonly _store = inject(FComponentsStore);
1617

1718
public handle(request: CalculateInputConnectionsRequest): FConnectionBase[] {
18-
return this._calculateConnections(
19-
new Set(this._calculateConnectors(request.fNode)),
20-
);
19+
return this._calculateConnections(new Set(this._calculateConnectors(request.fNode)));
2120
}
2221

2322
private _calculateConnectors(fNode: FNodeBase): string[] {
24-
return this._store.fInputs
25-
.filter((x) => fNode.isContains(x.hostElement))
26-
.map((x) => x.fId);
23+
return this._store.fInputs.filter((x) => fNode.isContains(x.hostElement)).map((x) => x.fId());
2724
}
2825

2926
private _calculateConnections(ids: Set<string>): FConnectionBase[] {
30-
return this._store.fConnections
31-
.filter((x) => ids.has(x.fInputId));
27+
return this._store.fConnections.filter((x) => ids.has(x.fInputId));
3228
}
3329
}

projects/f-flow/src/domain/f-node/calculate-output-connections/calculate-output-connections.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,19 @@ import { FConnectionBase } from '../../../f-connection';
1111
@Injectable()
1212
@FExecutionRegister(CalculateOutputConnectionsRequest)
1313
export class CalculateOutputConnections
14-
implements IExecution<CalculateOutputConnectionsRequest, FConnectionBase[]> {
15-
14+
implements IExecution<CalculateOutputConnectionsRequest, FConnectionBase[]>
15+
{
1616
private readonly _store = inject(FComponentsStore);
1717

1818
public handle(request: CalculateOutputConnectionsRequest): FConnectionBase[] {
19-
return this._calculateConnections(
20-
new Set(this._calculateConnectors(request.fNode)),
21-
);
19+
return this._calculateConnections(new Set(this._calculateConnectors(request.fNode)));
2220
}
2321

2422
private _calculateConnectors(fNode: FNodeBase): string[] {
25-
return this._store.fOutputs
26-
.filter((x) => fNode.isContains(x.hostElement))
27-
.map((x) => x.fId);
23+
return this._store.fOutputs.filter((x) => fNode.isContains(x.hostElement)).map((x) => x.fId());
2824
}
2925

3026
private _calculateConnections(ids: Set<string>): FConnectionBase[] {
31-
return this._store.fConnections
32-
.filter((x) => ids.has(x.fOutputId));
27+
return this._store.fConnections.filter((x) => ids.has(x.fOutputId));
3328
}
3429
}

0 commit comments

Comments
 (0)