Skip to content

refactor: constructor breaking changes for 8.0 #15647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 11 additions & 41 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import {Directionality} from '@angular/cdk/bidi';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {DOCUMENT} from '@angular/common';
import {
AfterViewInit,
Expand All @@ -33,7 +32,6 @@ import {
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
import {Observable, Observer, Subject, merge} from 'rxjs';
import {startWith, take, map, takeUntil, switchMap, tap} from 'rxjs/operators';
import {DragDropRegistry} from '../drag-drop-registry';
import {
CdkDragDrop,
CdkDragEnd,
Expand All @@ -49,7 +47,6 @@ import {CdkDragPreview} from './drag-preview';
import {CDK_DROP_LIST} from '../drop-list-container';
import {CDK_DRAG_PARENT} from '../drag-parent';
import {DragRef, DragRefConfig, Point} from '../drag-ref';
import {DropListRef} from '../drop-list-ref';
import {CdkDropListInternal as CdkDropList} from './drop-list';
import {DragDrop} from '../drag-drop';

Expand Down Expand Up @@ -182,36 +179,15 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
});

constructor(
/** Element that the draggable is attached to. */
public element: ElementRef<HTMLElement>,
/** Droppable container that the draggable is a part of. */
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf()
public dropContainer: CdkDropList,
@Inject(DOCUMENT) private _document: any,
private _ngZone: NgZone,
private _viewContainerRef: ViewContainerRef,
viewportRuler: ViewportRuler,
dragDropRegistry: DragDropRegistry<DragRef, DropListRef>,
@Inject(CDK_DRAG_CONFIG) config: DragRefConfig,
@Optional() private _dir: Directionality,

/**
* @deprecated `viewportRuler`, `dragDropRegistry` and `_changeDetectorRef` parameters
* to be removed. Also `dragDrop` parameter to be made required.
* @breaking-change 8.0.0.
*/
dragDrop?: DragDrop,
private _changeDetectorRef?: ChangeDetectorRef) {


// @breaking-change 8.0.0 Remove null check once the paramter is made required.
if (dragDrop) {
this._dragRef = dragDrop.createDrag(element, config);
} else {
this._dragRef = new DragRef(element, config, _document, _ngZone, viewportRuler,
dragDropRegistry);
}

/** Element that the draggable is attached to. */
public element: ElementRef<HTMLElement>,
/** Droppable container that the draggable is a part of. */
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf() public dropContainer: CdkDropList,
@Inject(DOCUMENT) private _document: any, private _ngZone: NgZone,
private _viewContainerRef: ViewContainerRef, @Inject(CDK_DRAG_CONFIG) config: DragRefConfig,
@Optional() private _dir: Directionality, dragDrop: DragDrop,
private _changeDetectorRef: ChangeDetectorRef) {
this._dragRef = dragDrop.createDrag(element, config);
this._dragRef.data = this;
this._syncInputs(this._dragRef);
this._handleEvents(this._dragRef);
Expand Down Expand Up @@ -361,10 +337,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {

// Since all of these events run outside of change detection,
// we need to ensure that everything is marked correctly.
if (this._changeDetectorRef) {
// @breaking-change 8.0.0 Remove null check for _changeDetectorRef
this._changeDetectorRef.markForCheck();
}
this._changeDetectorRef.markForCheck();
});

ref.released.subscribe(() => {
Expand All @@ -376,10 +349,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {

// Since all of these events run outside of change detection,
// we need to ensure that everything is marked correctly.
if (this._changeDetectorRef) {
// @breaking-change 8.0.0 Remove null check for _changeDetectorRef
this._changeDetectorRef.markForCheck();
}
this._changeDetectorRef.markForCheck();
});

ref.entered.subscribe(event => {
Expand Down
30 changes: 5 additions & 25 deletions src/cdk/drag-drop/directives/drop-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ import {
Directive,
ChangeDetectorRef,
SkipSelf,
Inject,
AfterContentInit,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Directionality} from '@angular/cdk/bidi';
import {CdkDrag} from './drag';
import {DragDropRegistry} from '../drag-drop-registry';
import {CdkDragDrop, CdkDragEnter, CdkDragExit, CdkDragSortEvent} from '../drag-events';
import {CDK_DROP_LIST_CONTAINER, CdkDropListContainer} from '../drop-list-container';
import {CdkDropListGroup} from './drop-list-group';
Expand Down Expand Up @@ -154,28 +151,11 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
sorted: EventEmitter<CdkDragSortEvent<T>> = new EventEmitter<CdkDragSortEvent<T>>();

constructor(
/** Element that the drop list is attached to. */
public element: ElementRef<HTMLElement>,
dragDropRegistry: DragDropRegistry<DragRef, DropListRef>,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() private _dir?: Directionality,
@Optional() @SkipSelf() private _group?: CdkDropListGroup<CdkDropList>,
@Optional() @Inject(DOCUMENT) _document?: any,

/**
* @deprecated `dragDropRegistry` and `_document` parameters to be removed.
* Also `dragDrop` parameter to be made required.
* @breaking-change 8.0.0.
*/
dragDrop?: DragDrop) {

// @breaking-change 8.0.0 Remove null check once `dragDrop` parameter is made required.
if (dragDrop) {
this._dropListRef = dragDrop.createDropList(element);
} else {
this._dropListRef = new DropListRef(element, dragDropRegistry, _document || document);
}

/** Element that the drop list is attached to. */
public element: ElementRef<HTMLElement>, dragDrop: DragDrop,
private _changeDetectorRef: ChangeDetectorRef, @Optional() private _dir?: Directionality,
@Optional() @SkipSelf() private _group?: CdkDropListGroup<CdkDropList>) {
this._dropListRef = dragDrop.createDropList(element);
this._dropListRef.data = this;
this._dropListRef.enterPredicate = (drag: DragRef<CdkDrag>, drop: DropListRef<CdkDropList>) => {
return this.enterPredicate(drag.data, drop.data);
Expand Down
28 changes: 13 additions & 15 deletions src/cdk/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
*/

import {Direction} from '@angular/cdk/bidi';
import {Platform} from '@angular/cdk/platform';
import {CdkScrollable, ViewportRuler} from '@angular/cdk/scrolling';
import {ElementRef} from '@angular/core';
import {Observable} from 'rxjs';

import {OverlayContainer} from '../overlay-container';
import {OverlayReference} from '../overlay-reference';

import {
ConnectedOverlayPositionChange,
ConnectionPositionPair,
Expand All @@ -18,8 +23,6 @@ import {
} from './connected-position';
import {FlexibleConnectedPositionStrategy} from './flexible-connected-position-strategy';
import {PositionStrategy} from './position-strategy';
import {Platform} from '@angular/cdk/platform';
import {OverlayReference} from '../overlay-reference';

/**
* A strategy for positioning overlays. Using this strategy, an overlay is given an
Expand Down Expand Up @@ -56,23 +59,18 @@ export class ConnectedPositionStrategy implements PositionStrategy {
}

constructor(
originPos: OriginConnectionPosition,
overlayPos: OverlayConnectionPosition,
connectedTo: ElementRef<HTMLElement>,
viewportRuler: ViewportRuler,
document: Document,
// @breaking-change 8.0.0 `platform` parameter to be made required.
platform?: Platform) {

originPos: OriginConnectionPosition, overlayPos: OverlayConnectionPosition,
connectedTo: ElementRef<HTMLElement>, viewportRuler: ViewportRuler, document: Document,
platform: Platform, overlayContainer: OverlayContainer) {
// Since the `ConnectedPositionStrategy` is deprecated and we don't want to maintain
// the extra logic, we create an instance of the positioning strategy that has some
// defaults that make it behave as the old position strategy and to which we'll
// proxy all of the API calls.
this._positionStrategy =
new FlexibleConnectedPositionStrategy(connectedTo, viewportRuler, document, platform)
.withFlexibleDimensions(false)
.withPush(false)
.withViewportMargin(0);
this._positionStrategy = new FlexibleConnectedPositionStrategy(
connectedTo, viewportRuler, document, platform, overlayContainer)
.withFlexibleDimensions(false)
.withPush(false)
.withViewportMargin(0);

this.withFallbackPosition(originPos, overlayPos);
}
Expand Down
19 changes: 6 additions & 13 deletions src/cdk/overlay/position/flexible-connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
}

constructor(
connectedTo: FlexibleConnectedPositionStrategyOrigin,
private _viewportRuler: ViewportRuler,
private _document: Document,
// @breaking-change 8.0.0 `_platform` and `_overlayContainer` parameters to be made required.
private _platform?: Platform,
private _overlayContainer?: OverlayContainer) {
connectedTo: FlexibleConnectedPositionStrategyOrigin, private _viewportRuler: ViewportRuler,
private _document: Document, private _platform: Platform,
private _overlayContainer: OverlayContainer) {
this.setOrigin(connectedTo);
}

Expand Down Expand Up @@ -193,8 +190,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
*/
apply(): void {
// We shouldn't do anything if the strategy was disposed or we're on the server.
// @breaking-change 8.0.0 Remove `_platform` null check once it's guaranteed to be defined.
if (this._isDisposed || (this._platform && !this._platform.isBrowser)) {
if (this._isDisposed || !this._platform.isBrowser) {
return;
}

Expand Down Expand Up @@ -926,11 +922,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
overlayPoint = this._pushOverlayOnScreen(overlayPoint, this._overlayRect, scrollPosition);
}

// @breaking-change 8.0.0 Currently the `_overlayContainer` is optional in order to avoid a
// breaking change. The null check here can be removed once the `_overlayContainer` becomes
// a required parameter.
let virtualKeyboardOffset = this._overlayContainer ?
this._overlayContainer.getContainerElement().getBoundingClientRect().top : 0;
let virtualKeyboardOffset =
this._overlayContainer.getContainerElement().getBoundingClientRect().top;

// Normally this would be zero, however when the overlay is attached to an input (e.g. in an
// autocomplete), mobile browsers will shift everything in order to put the input in the middle
Expand Down
21 changes: 10 additions & 11 deletions src/cdk/overlay/position/overlay-position-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Platform} from '@angular/cdk/platform';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {DOCUMENT} from '@angular/common';
import {ElementRef, Inject, Injectable, Optional} from '@angular/core';
import {ElementRef, Inject, Injectable} from '@angular/core';

import {OverlayContainer} from '../overlay-container';

import {OriginConnectionPosition, OverlayConnectionPosition} from './connected-position';
import {ConnectedPositionStrategy} from './connected-position-strategy';
import {
FlexibleConnectedPositionStrategy,
FlexibleConnectedPositionStrategyOrigin,
} from './flexible-connected-position-strategy';
import {GlobalPositionStrategy} from './global-position-strategy';
import {Platform} from '@angular/cdk/platform';
import {OverlayContainer} from '../overlay-container';


/** Builder for overlay position strategy. */
@Injectable({providedIn: 'root'})
export class OverlayPositionBuilder {
constructor(
private _viewportRuler: ViewportRuler,
@Inject(DOCUMENT) private _document: any,
// @breaking-change 8.0.0 `_platform` and `_overlayContainer` parameters to be made required.
@Optional() private _platform?: Platform,
@Optional() private _overlayContainer?: OverlayContainer) { }
private _viewportRuler: ViewportRuler, @Inject(DOCUMENT) private _document: any,
private _platform: Platform, private _overlayContainer: OverlayContainer) {}

/**
* Creates a global position strategy.
Expand All @@ -49,9 +48,9 @@ export class OverlayPositionBuilder {
elementRef: ElementRef,
originPos: OriginConnectionPosition,
overlayPos: OverlayConnectionPosition): ConnectedPositionStrategy {

return new ConnectedPositionStrategy(originPos, overlayPos, elementRef, this._viewportRuler,
this._document);
return new ConnectedPositionStrategy(
originPos, overlayPos, elementRef, this._viewportRuler, this._document, this._platform,
this._overlayContainer);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/cdk/schematics/ng-update/data/constructor-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export type ConstructorChecksUpgradeData = string;
* automatically through type checking.
*/
export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
[TargetVersion.V8]: [
{
pr: 'https://github.com/angular/material2/pull/15647',
changes: [
'CdkDrag', 'CdkDropList', 'ConnectedPositionStrategy', 'FlexibleConnectedPositionStrategy',
'OverlayPositionBuilder', 'CdkTable'
]
}
],
[TargetVersion.V7]: [],
[TargetVersion.V6]: []
};
19 changes: 5 additions & 14 deletions src/cdk/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,8 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
protected readonly _differs: IterableDiffers,
protected readonly _changeDetectorRef: ChangeDetectorRef,
protected readonly _elementRef: ElementRef, @Attribute('role') role: string,
@Optional() protected readonly _dir: Directionality,
/**
* @deprecated
* @breaking-change 8.0.0 `_document` and `_platform` to
* be made into a required parameters.
*/
@Inject(DOCUMENT) _document?: any, private _platform?: Platform) {
@Optional() protected readonly _dir: Directionality, @Inject(DOCUMENT) _document: any,
private _platform: Platform) {
if (!role) {
this._elementRef.nativeElement.setAttribute('role', 'grid');
}
Expand Down Expand Up @@ -1002,17 +997,15 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes

/** Adds native table sections (e.g. tbody) and moves the row outlets into them. */
private _applyNativeTableSections() {
// @breaking-change 8.0.0 remove the `|| document` once the `_document` is a required param.
const documentRef = this._document || document;
const documentFragment = documentRef.createDocumentFragment();
const documentFragment = this._document.createDocumentFragment();
const sections = [
{tag: 'thead', outlet: this._headerRowOutlet},
{tag: 'tbody', outlet: this._rowOutlet},
{tag: 'tfoot', outlet: this._footerRowOutlet},
];

for (const section of sections) {
const element = documentRef.createElement(section.tag);
const element = this._document.createElement(section.tag);
element.setAttribute('role', 'rowgroup');
element.appendChild(section.outlet.elementRef.nativeElement);
documentFragment.appendChild(element);
Expand Down Expand Up @@ -1069,9 +1062,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
private _setupStickyStyler() {
const direction: Direction = this._dir ? this._dir.value : 'ltr';
this._stickyStyler = new StickyStyler(
this._isNativeHtmlTable,
// @breaking-change 8.0.0 remove the null check for `this._platform`.
this.stickyCssClass, direction, this._platform ? this._platform.isBrowser : true);
this._isNativeHtmlTable, this.stickyCssClass, direction, this._platform.isBrowser);
(this._dir ? this._dir.change : observableOf<Direction>())
.pipe(takeUntil(this._onDestroy))
.subscribe(value => {
Expand Down
Loading