Skip to content

Commit

Permalink
feat: Moved to FMediator execute
Browse files Browse the repository at this point in the history
  • Loading branch information
siarheihuzarevich committed Jan 31, 2025
1 parent 84a0054 commit 109fd15
Show file tree
Hide file tree
Showing 71 changed files with 175 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CenterGroupOrNodeExecution implements IExecution<CenterGroupOrNodeR

this.toCenter(this.getNodeRect(fNode), this.getFlowRect(), fNode.position);

this._fMediator.send(new RedrawCanvasWithAnimationRequest(request.animated));
this._fMediator.execute(new RedrawCanvasWithAnimationRequest(request.animated));
}

public toCenter(fNodeRect: IRect, fFlowRect: IRect, position: IPoint): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FitToFlowExecution implements IExecution<FitToFlowRequest, void> {
private _fMediator = inject(FMediator);

public handle(request: FitToFlowRequest): void {
const fNodesRect = this._fMediator.send<IRect | null>(new CalculateNodesBoundingBoxRequest()) || RectExtensions.initialize();
const fNodesRect = this._fMediator.execute<IRect | null>(new CalculateNodesBoundingBoxRequest()) || RectExtensions.initialize();
if (fNodesRect.width === 0 || fNodesRect.height === 0) {
return;
}
Expand All @@ -30,7 +30,7 @@ export class FitToFlowExecution implements IExecution<FitToFlowRequest, void> {
request.toCenter
);

this._fMediator.send(new RedrawCanvasWithAnimationRequest(request.animated));
this._fMediator.execute(new RedrawCanvasWithAnimationRequest(request.animated));
}

public fitToParent(rect: IRect, parentRect: IRect, points: IPoint[], toCenter: IPoint): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ResetScaleAndCenterExecution implements IExecution<ResetScaleAndCen
private _fMediator = inject(FMediator);

public handle(request: ResetScaleAndCenterRequest): void {
const fNodesRect = this._fMediator.send<IRect | null>(new CalculateNodesBoundingBoxRequest()) || RectExtensions.initialize();
const fNodesRect = this._fMediator.execute<IRect | null>(new CalculateNodesBoundingBoxRequest()) || RectExtensions.initialize();
if (fNodesRect.width === 0 || fNodesRect.height === 0) {
return;
}
Expand All @@ -28,7 +28,7 @@ export class ResetScaleAndCenterExecution implements IExecution<ResetScaleAndCen
this._fComponentsStore.fNodes.map((x) => x.position)
);

this._fMediator.send(new RedrawCanvasWithAnimationRequest(request.animated));
this._fMediator.execute(new RedrawCanvasWithAnimationRequest(request.animated));
}

public oneToOneCentering(rect: IRect, parentRect: IRect, points: IPoint[]): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('CalculateConnectionLineByBehaviorExecution', () => {
});

it('should handle floating behavior correctly', () => {
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
const result: ILine = fMediator.execute(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand All @@ -35,7 +35,7 @@ describe('CalculateConnectionLineByBehaviorExecution', () => {
});

it('should handle fixed center behavior correctly', () => {
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
const result: ILine = fMediator.execute(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand All @@ -54,7 +54,7 @@ describe('CalculateConnectionLineByBehaviorExecution', () => {
});

it('should handle fixed outbound behavior correctly', () => {
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
const result: ILine = fMediator.execute(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
}

private setMarkers(connection: FConnectionBase): void {
this.fMediator.send(
this.fMediator.execute(
new CreateConnectionMarkersRequest(connection)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ describe('CalculateClosestInputExecution', () => {
});

it('should return undefined when canBeConnectedInputs is empty', () => {
const result = fMediator.send(
const result = fMediator.execute(
new CalculateClosestInputRequest({ x: 50, y: 50 }, [])
);
expect(result).toBeUndefined();
});

it('should return the only element if its distance is less than snapThreshold', () => {

const result = fMediator.send<IClosestInput>(
const result = fMediator.execute<IClosestInput>(
new CalculateClosestInputRequest({ x: 10, y: 10 }, [ {
fConnector: {
fId: 'input1'
Expand All @@ -45,7 +45,7 @@ describe('CalculateClosestInputExecution', () => {
});

it('should return 10 if the only element is exactly at snapThreshold distance', () => {
const result = fMediator.send<IClosestInput>(
const result = fMediator.execute<IClosestInput>(
new CalculateClosestInputRequest({ x: 0, y: 0 }, [ {
fConnector: {
fId: 'input1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class FindInputAtPositionExecution
}
const position = Point.fromPoint(request.toConnectorRect).add(this._calculateDifference(request.pointerPosition));

const fClosestInput = this._fMediator.send<IClosestInput | undefined>(
const fClosestInput = this._fMediator.execute<IClosestInput | undefined>(
new CalculateClosestInputRequest(position, request.canBeConnectedInputs)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class GetConnectorAndRectExecution implements IExecution<GetConnectorAndR
}

private _getConnectorRect(fConnector: FConnectorBase): IRoundedRect {
return this._fMediator.send<IRoundedRect>(new GetNormalizedElementRectRequest(fConnector.hostElement, true));
return this._fMediator.execute<IRoundedRect>(new GetNormalizedElementRectRequest(fConnector.hostElement, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class EmitSelectionChangeEventExecution implements IExecution<EmitSelecti

this._emitSelectionChange(this._getSelection());
this._fDraggableDataContext.isSelectedChanged = false;
this._fMediator.send<void>(new NotifyTransformChangedRequest());
this._fMediator.execute<void>(new NotifyTransformChangedRequest());
}

private _getSelection(): ICurrentSelection {
return this._fMediator.send<ICurrentSelection>(new GetCurrentSelectionRequest());
return this._fMediator.execute<ICurrentSelection>(new GetCurrentSelectionRequest());
}

private _emitSelectionChange(selection: ICurrentSelection): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class StartDragSequenceExecution implements IExecution<StartDragSequenceR
public handle(request: StartDragSequenceRequest): void {
if (this._fDraggableDataContext.draggableItems.length > 0) {
this._hostElement.classList.add(F_CSS_CLASS.DRAG_AND_DROP.DRAGGING);
this._fMediator.send<void>(new EmitSelectionChangeEventRequest());
this._fMediator.execute<void>(new EmitSelectionChangeEventRequest());
this._emitDragStarted();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class GetFlowStateExecution implements IExecution<GetFlowStateRequest, IF
return {
position: this._getCanvasPosition(this._fComponentsStore.fCanvas!.transform),
scale: this._fComponentsStore.fCanvas!.transform.scale,
nodes: this._fMediator.send(new GetFlowStateNodesRequest(FNodeDirective)),
groups: this._fMediator.send(new GetFlowStateNodesRequest(FGroupDirective)),
connections: this._fMediator.send(new GetFlowStateConnectionsRequest())
nodes: this._fMediator.execute(new GetFlowStateNodesRequest(FNodeDirective)),
groups: this._fMediator.execute(new GetFlowStateNodesRequest(FGroupDirective)),
connections: this._fMediator.execute(new GetFlowStateConnectionsRequest())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GetCanBeSelectedItemsExecution implements IExecution<void, ICanBeSe
return {
element: x,
fRect: RectExtensions.mult(
this._fMediator.send<IRect>(new GetNormalizedElementRectRequest(x.hostElement, false)),
this._fMediator.execute<IRect>(new GetNormalizedElementRectRequest(x.hostElement, false)),
this.transform.scale
)
};
Expand All @@ -52,7 +52,7 @@ export class GetCanBeSelectedItemsExecution implements IExecution<void, ICanBeSe
return {
element: x,
fRect: RectExtensions.mult(
this._fMediator.send<IRect>(new GetNormalizedElementRectRequest(x.boundingElement, false)),
this._fMediator.execute<IRect>(new GetNormalizedElementRectRequest(x.boundingElement, false)),
this.transform.scale
)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('GetSelectionExecution', () => {
];
fDraggableDataContext.selectedItems = mockSelectedItems as any;

const result = fMediator.send<FSelectionChangeEvent>(new GetCurrentSelectionRequest());
const result = fMediator.execute<FSelectionChangeEvent>(new GetCurrentSelectionRequest());

expect(result.nodes).toEqual([ 'node1' ]);
expect(result.groups).toEqual([ 'group1' ]);
Expand All @@ -51,7 +51,7 @@ describe('GetSelectionExecution', () => {
it('should return empty FSelectionChangeEvent when no items are selected', () => {
fDraggableDataContext.selectedItems = [];

const result = fMediator.send<FSelectionChangeEvent>(new GetCurrentSelectionRequest());
const result = fMediator.execute<FSelectionChangeEvent>(new GetCurrentSelectionRequest());

expect(result.nodes).toEqual([]);
expect(result.connections).toEqual([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('SelectAllExecution', () => {
];
fDraggableDataContext.selectedItems = mockSelectedItems as any;

fMediator.send(new SelectAllRequest());
fMediator.execute(new SelectAllRequest());

mockSelectedItems.forEach(item => {
expect(item.unmarkAsSelected).toHaveBeenCalled();
Expand All @@ -42,7 +42,7 @@ describe('SelectAllExecution', () => {
fComponentsStore.fConnections = [mockConnection] as any;
fDraggableDataContext.selectedItems = [];

fMediator.send(new SelectAllRequest());
fMediator.execute(new SelectAllRequest());

expect(mockNode.markAsSelected).toHaveBeenCalled();
expect(mockConnection.markAsSelected).toHaveBeenCalled();
Expand All @@ -55,7 +55,7 @@ describe('SelectAllExecution', () => {
fComponentsStore.fConnections = [] as any;
fDraggableDataContext.selectedItems = [];

fMediator.send(new SelectAllRequest());
fMediator.execute(new SelectAllRequest());

expect(fDraggableDataContext.selectedItems.length).toBe(0);
expect(fDraggableDataContext.isSelectedChanged).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SelectAndUpdateNodeLayerExecution implements IHandler<SelectAndUpda
public handle(request: SelectAndUpdateNodeLayerRequest): void {
this.selectNodeIfNotSelected(request.fNode);

this.fMediator.send<void>(
this.fMediator.execute<void>(
new UpdateItemAndChildrenLayersRequest(request.fNode, request.fNode.hostElement.parentElement as HTMLElement)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('SelectExecution', () => {
];
fDraggableDataContext.selectedItems = mockSelectedItems as any;

fMediator.send(new SelectRequest([], []));
fMediator.execute(new SelectRequest([], []));

mockSelectedItems.forEach(item => {
expect(item.unmarkAsSelected).toHaveBeenCalled();
Expand All @@ -42,7 +42,7 @@ describe('SelectExecution', () => {
fComponentsStore.fConnections = [mockConnection] as any;
fDraggableDataContext.selectedItems = [];

fMediator.send(new SelectRequest(['node1'], ['conn1']));
fMediator.execute(new SelectRequest(['node1'], ['conn1']));

expect(mockNode.markAsSelected).toHaveBeenCalled();
expect(mockConnection.markAsSelected).toHaveBeenCalled();
Expand All @@ -55,7 +55,7 @@ describe('SelectExecution', () => {
fComponentsStore.fConnections = [] as any;
fDraggableDataContext.selectedItems = [];

fMediator.send(new SelectRequest(['nonexistentNode'], ['nonexistentConnection']));
fMediator.execute(new SelectRequest(['nonexistentNode'], ['nonexistentConnection']));

expect(fDraggableDataContext.selectedItems.length).toBe(0);
expect(fDraggableDataContext.isSelectedChanged).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GetNormalizedElementRectExecution implements IExecution<GetNormaliz
}

private _getElementRoundedRect(request: GetNormalizedElementRectRequest): IRoundedRect {
return request.isRoundedRect ? this._fMediator.send<IRoundedRect>(
return request.isRoundedRect ? this._fMediator.execute<IRoundedRect>(
new GetElementRoundedRectRequest(request.element)
) : RoundedRect.fromRect(RectExtensions.fromElement(request.element));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('SortItemLayersExecution, SortNodeLayersByGroups, SortItemsByParent', (

fComponentsStore.fNodes = [ group1, group2, node1, node2, node3 ];

fMediator.send(new SortItemLayersRequest());
fMediator.execute(new SortItemLayersRequest());

expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(0)).toEqual(node2.hostElement);
expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(1)).toEqual(node3.hostElement);
Expand All @@ -80,7 +80,7 @@ describe('SortItemLayersExecution, SortNodeLayersByGroups, SortItemsByParent', (

fComponentsStore.fNodes = [ group1, group2, node1, node2 ];

fMediator.send(new SortItemLayersRequest());
fMediator.execute(new SortItemLayersRequest());

expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(0)).toEqual(node1.hostElement);
expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(1)).toEqual(node2.hostElement);
Expand All @@ -102,7 +102,7 @@ describe('SortItemLayersExecution, SortNodeLayersByGroups, SortItemsByParent', (

fComponentsStore.fNodes = [ group1, group2, node1, node2 ];

fMediator.send(new SortItemLayersRequest());
fMediator.execute(new SortItemLayersRequest());

expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(0)).toEqual(node2.hostElement);
expect(fComponentsStore.fCanvas.fNodesContainer.nativeElement.children.item(1)).toEqual(node1.hostElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class SortItemLayersExecution implements IExecution<SortItemLayersRequest
if(!this.fComponentsStore.fCanvas) {
return;
}
this.fMediator.send(new SortItemsByParentRequest(this.fComponentsStore.fCanvas.fGroupsContainer.nativeElement));
this.fMediator.send(new SortNodeLayersRequest());
this.fMediator.send(new SortItemsByParentRequest(this.fComponentsStore.fCanvas.fNodesContainer.nativeElement));
this.fMediator.execute(new SortItemsByParentRequest(this.fComponentsStore.fCanvas.fGroupsContainer.nativeElement));
this.fMediator.execute(new SortNodeLayersRequest());
this.fMediator.execute(new SortItemsByParentRequest(this.fComponentsStore.fCanvas.fNodesContainer.nativeElement));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SortItemsByParentExecution implements IExecution<SortItemsByParentR
}

private _getChildrenItems(fId: string): HTMLElement[] {
return this.fMediator.send<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId))
return this.fMediator.execute<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId))
.filter((x) => this.fItemsContainer.contains(x.hostElement)).map((x) => x.hostElement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SortNodeLayersExecution implements IExecution<SortNodeLayersRequest
}

private getChildrenNodes(fId: string): HTMLElement[] {
return this.fMediator.send<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId))
return this.fMediator.execute<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId))
.filter((x) => this.fNodesContainer.contains(x.hostElement)).map((x) => x.hostElement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('UpdateItemAndChildrenLayersExecution', () => {
fCanvas.fNodesContainer.nativeElement.append(node4.hostElement, node1.hostElement, node2.hostElement, node3.hostElement);

fComponentsStore.fNodes = [ group1, group2, node1, node2, node3, node4 ];
fMediator.send(new SortItemLayersRequest());
fMediator.send(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement));
fMediator.execute(new SortItemLayersRequest());
fMediator.execute(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement));

expect(fCanvas.fGroupsContainer.nativeElement.children.item(0)).toEqual(group2.hostElement);
expect(fCanvas.fGroupsContainer.nativeElement.children.item(1)).toEqual(group1.hostElement);
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('UpdateItemAndChildrenLayersExecution', () => {

fComponentsStore.fNodes = [ group1, group2, node1, node2, node3, node4 ];

fMediator.send(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement));
fMediator.execute(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement));

expect(fCanvas.fGroupsContainer.nativeElement.children.item(0)).toEqual(group2.hostElement);
expect(fCanvas.fGroupsContainer.nativeElement.children.item(1)).toEqual(group1.hostElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class UpdateItemAndChildrenLayersExecution implements IExecution<UpdateIt
const allElements = Array.from(itemContainer.children) as HTMLElement[];
const targetIndex = allElements.findIndex((x) => x === item);
if (this.isAnythingNeedToBeMoved(allElements, targetIndex, elementsThatShouldBeInFront)) {
this.fMediator.send(
this.fMediator.execute(
new MoveFrontElementsBeforeTargetElementRequest(itemContainer, allElements, elementsThatShouldBeInFront, targetIndex)
);
}
Expand Down Expand Up @@ -97,6 +97,6 @@ export class UpdateItemAndChildrenLayersExecution implements IExecution<UpdateIt
}

private getChildrenNodesAndGroups(fId: string): HTMLElement[] {
return this.fMediator.send<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId)).map((x) => x.hostElement);
return this.fMediator.execute<FNodeBase[]>(new GetDeepChildrenNodesAndGroupsRequest(fId)).map((x) => x.hostElement);
}
}
6 changes: 3 additions & 3 deletions projects/f-flow/src/f-backgroud/f-background.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ export class FBackgroundComponent
private _fMediator = inject(FMediator);

public ngOnInit(): void {
this._fMediator.send(new AddBackgroundToStoreRequest(this));
this._fMediator.execute(new AddBackgroundToStoreRequest(this));
}

public ngAfterContentInit(): void {
this._fMediator.send(new AddPatternToBackgroundRequest(this.fBackgroundPattern!));
this._fMediator.execute(new AddPatternToBackgroundRequest(this.fBackgroundPattern!));
}

public setTransform(transform: ITransformModel): void {
this.fBackgroundPattern?.setTransform(transform);
}

public ngOnDestroy() {
this._fMediator.send(new RemoveBackgroundFromStoreRequest(this));
this._fMediator.execute(new RemoveBackgroundFromStoreRequest(this));
}
}
Loading

0 comments on commit 109fd15

Please sign in to comment.