Skip to content

Commit 3814357

Browse files
committed
refactor(popover-edit): remove circular reference
Reworks the popover edit module in order to avoid circular references.
1 parent f428c00 commit 3814357

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

goldens/ts-circular-deps.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
"src/cdk-experimental/menu/menu-panel.ts",
99
"src/cdk-experimental/menu/menu.ts"
1010
],
11-
[
12-
"src/cdk-experimental/popover-edit/edit-event-dispatcher.ts",
13-
"src/cdk-experimental/popover-edit/edit-ref.ts"
14-
],
1511
[
1612
"src/cdk/drag-drop/directives/drag.ts",
1713
"src/cdk/drag-drop/directives/drop-list.ts"

src/cdk-experimental/popover-edit/edit-event-dispatcher.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222

2323
import {CELL_SELECTOR, ROW_SELECTOR} from './constants';
2424
import {closest} from './polyfill';
25-
import {EditRef} from './edit-ref';
2625

2726
/** The delay applied to mouse events before hiding or showing hover content. */
2827
const MOUSE_EVENT_DELAY_MS = 40;
@@ -42,11 +41,15 @@ export const enum HoverContentState {
4241
ON,
4342
}
4443

44+
// Note: this class is generic, rather than referencing EditRef directly, in order to avoid
45+
// circular imports. If we were to reference it here, importing the registry into the
46+
// class that is registering itself will introduce a circular import.
47+
4548
/**
4649
* Service for sharing delegated events and state for triggering table edits.
4750
*/
4851
@Injectable()
49-
export class EditEventDispatcher {
52+
export class EditEventDispatcher<R> {
5053
/** A subject that indicates which table cell is currently editing (unless it is disabled). */
5154
readonly editing = new Subject<Element|null>();
5255

@@ -70,10 +73,10 @@ export class EditEventDispatcher {
7073
readonly disabledCells = new WeakMap<Element, boolean>();
7174

7275
/** The EditRef for the currently active edit lens (if any). */
73-
get editRef(): EditRef<any>|null {
76+
get editRef(): R|null {
7477
return this._editRef;
7578
}
76-
private _editRef: EditRef<any>|null = null;
79+
private _editRef: R|null = null;
7780

7881
// Optimization: Precompute common pipeable operators used per row/cell.
7982
private readonly _distinctUntilChanged =
@@ -181,12 +184,12 @@ export class EditEventDispatcher {
181184
}
182185

183186
/** Sets the currently active EditRef. */
184-
setActiveEditRef(ref: EditRef<any>) {
187+
setActiveEditRef(ref: R) {
185188
this._editRef = ref;
186189
}
187190

188191
/** Unsets the currently active EditRef, if the specified editRef is active. */
189-
unsetActiveEditRef(ref: EditRef<any>) {
192+
unsetActiveEditRef(ref: R) {
190193
if (this._editRef !== ref) {
191194
return;
192195
}

src/cdk-experimental/popover-edit/edit-ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class EditRef<FormValue> implements OnDestroy {
3232

3333
constructor(
3434
@Self() private readonly _form: ControlContainer,
35-
private readonly _editEventDispatcher: EditEventDispatcher,
35+
private readonly _editEventDispatcher: EditEventDispatcher<EditRef<FormValue>>,
3636
private readonly _ngZone: NgZone) {
3737
this._editEventDispatcher.setActiveEditRef(this);
3838
}

src/cdk-experimental/popover-edit/edit-services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1515
import {EditEventDispatcher} from './edit-event-dispatcher';
1616
import {FocusDispatcher} from './focus-dispatcher';
1717
import {PopoverEditPositionStrategyFactory} from './popover-edit-position-strategy-factory';
18+
import {EditRef} from './edit-ref';
1819

1920
/**
2021
* Optimization
@@ -26,7 +27,8 @@ import {PopoverEditPositionStrategyFactory} from './popover-edit-position-strate
2627
export class EditServices {
2728
constructor(
2829
readonly directionality: Directionality,
29-
readonly editEventDispatcher: EditEventDispatcher, readonly focusDispatcher: FocusDispatcher,
30+
readonly editEventDispatcher: EditEventDispatcher<EditRef<unknown>>,
31+
readonly focusDispatcher: FocusDispatcher,
3032
readonly focusTrapFactory: FocusTrapFactory, readonly ngZone: NgZone,
3133
readonly overlay: Overlay, readonly positionFactory: PopoverEditPositionStrategyFactory,
3234
readonly scrollDispatcher: ScrollDispatcher, readonly viewportRuler: ViewportRuler) {}

src/cdk-experimental/popover-edit/table-directives.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
FocusEscapeNotifierFactory
4242
} from './focus-escape-notifier';
4343
import {closest} from './polyfill';
44+
import {EditRef} from './edit-ref';
4445

4546
/**
4647
* Describes the number of columns before and after the originating cell that the
@@ -69,7 +70,7 @@ export class CdkEditable implements AfterViewInit, OnDestroy {
6970

7071
constructor(
7172
protected readonly elementRef: ElementRef,
72-
protected readonly editEventDispatcher: EditEventDispatcher,
73+
protected readonly editEventDispatcher: EditEventDispatcher<EditRef<unknown>>,
7374
protected readonly focusDispatcher: FocusDispatcher, protected readonly ngZone: NgZone) {}
7475

7576
ngAfterViewInit(): void {
@@ -488,7 +489,7 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
488489
export class CdkEditOpen {
489490
constructor(
490491
protected readonly elementRef: ElementRef<HTMLElement>,
491-
protected readonly editEventDispatcher: EditEventDispatcher) {
492+
protected readonly editEventDispatcher: EditEventDispatcher<EditRef<unknown>>) {
492493

493494
const nativeElement = elementRef.nativeElement;
494495

0 commit comments

Comments
 (0)