Skip to content

Commit 5c8feac

Browse files
committed
refactor(material/core): deprecate TypeScript mixin functions (#28673)
Marks the TypeScript mixin functions and their related interfaces as deprecated since they are difficult to use and not really necessary now that we have input transforms. (cherry picked from commit 94306f3)
1 parent afbb34e commit 5c8feac

File tree

9 files changed

+71
-25
lines changed

9 files changed

+71
-25
lines changed

src/cdk/table/can-stick.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type CanStickCtor = Constructor<CanStick>;
3636
* changed since the last time the function was called. Essentially adds a dirty-check to the
3737
* sticky value.
3838
* @docs-private
39+
* @deprecated Implement the `CanStick` interface instead.
40+
* @breaking-change 19.0.0
3941
*/
4042
export function mixinHasStickyInput<T extends Constructor<{}>>(base: T): CanStickCtor & T {
4143
return class extends base {

src/material/core/common-behaviors/color.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import {AbstractConstructor, Constructor} from './constructor';
1010
import {ElementRef} from '@angular/core';
1111

12-
/** @docs-private */
12+
/**
13+
* @docs-private
14+
* @deprecated Will be removed together with `mixinColor`.
15+
* @breaking-change 19.0.0
16+
*/
1317
export interface CanColor {
1418
/** Theme color palette for the component. */
1519
color: ThemePalette;
@@ -21,14 +25,18 @@ export interface CanColor {
2125
type CanColorCtor = Constructor<CanColor> & AbstractConstructor<CanColor>;
2226

2327
/** @docs-private */
24-
export interface HasElementRef {
28+
interface HasElementRef {
2529
_elementRef: ElementRef;
2630
}
2731

2832
/** Possible color palette values. */
2933
export type ThemePalette = 'primary' | 'accent' | 'warn' | undefined;
3034

31-
/** Mixin to augment a directive with a `color` property. */
35+
/**
36+
* Mixin to augment a directive with a `color` property.
37+
* @deprecated Use a plain input and host bindings instead.
38+
* @breaking-change 19.0.0
39+
*/
3240
export function mixinColor<T extends AbstractConstructor<HasElementRef>>(
3341
base: T,
3442
defaultColor?: ThemePalette,

src/material/core/common-behaviors/disable-ripple.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {AbstractConstructor, Constructor} from './constructor';
1111

12-
/** @docs-private */
12+
/**
13+
* @docs-private
14+
* @deprecated Will be removed together with `mixinDisableRipple`.
15+
* @breaking-change 19.0.0
16+
*/
1317
export interface CanDisableRipple {
1418
/** Whether ripples are disabled. */
1519
disableRipple: boolean;
1620
}
1721

1822
type CanDisableRippleCtor = Constructor<CanDisableRipple> & AbstractConstructor<CanDisableRipple>;
1923

20-
/** Mixin to augment a directive with a `disableRipple` property. */
24+
/**
25+
* Mixin to augment a directive with a `disableRipple` property.
26+
* @deprecated Use an input with a transform instead.
27+
* @breaking-change 19.0.0
28+
*/
2129
export function mixinDisableRipple<T extends AbstractConstructor<{}>>(
2230
base: T,
2331
): CanDisableRippleCtor & T;

src/material/core/common-behaviors/disabled.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {AbstractConstructor, Constructor} from './constructor';
1111

12-
/** @docs-private */
12+
/**
13+
* @docs-private
14+
* @deprecated Will be removed together with `mixinDisabled`.
15+
* @breaking-change 19.0.0
16+
*/
1317
export interface CanDisable {
1418
/** Whether the component is disabled. */
1519
disabled: boolean;
1620
}
1721

1822
type CanDisableCtor = Constructor<CanDisable> & AbstractConstructor<CanDisable>;
1923

20-
/** Mixin to augment a directive with a `disabled` property. */
24+
/**
25+
* Mixin to augment a directive with a `disabled` property.
26+
* @deprecated Use an input with a transform instead.
27+
* @breaking-change 19.0.0
28+
*/
2129
export function mixinDisabled<T extends AbstractConstructor<{}>>(base: T): CanDisableCtor & T;
2230
export function mixinDisabled<T extends Constructor<{}>>(base: T): CanDisableCtor & T {
2331
return class extends base {

src/material/core/common-behaviors/error-state.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {AbstractConstructor, Constructor} from './constructor';
1414
// Declare ErrorStateMatcher as an interface to have compatibility with Closure Compiler.
1515
interface ErrorStateMatcher extends _ErrorStateMatcher {}
1616

17-
/** @docs-private */
17+
/**
18+
* @docs-private
19+
* @deprecated Will be removed together with `mixinErrorState`.
20+
* @breaking-change 19.0.0
21+
*/
1822
export interface CanUpdateErrorState {
1923
/** Updates the error state based on the provided error state matcher. */
2024
updateErrorState(): void;
@@ -28,7 +32,7 @@ type CanUpdateErrorStateCtor = Constructor<CanUpdateErrorState> &
2832
AbstractConstructor<CanUpdateErrorState>;
2933

3034
/** @docs-private */
31-
export interface HasErrorState {
35+
interface HasErrorState {
3236
_parentFormGroup: FormGroupDirective;
3337
_parentForm: NgForm;
3438
_defaultErrorStateMatcher: ErrorStateMatcher;
@@ -77,6 +81,8 @@ export class _ErrorStateTracker {
7781
/**
7882
* Mixin to augment a directive with updateErrorState method.
7983
* For component with `errorState` and need to update `errorState`.
84+
* @deprecated Implement the `updateErrorState` method directly.
85+
* @breaking-change 19.0.0
8086
*/
8187
export function mixinErrorState<T extends AbstractConstructor<HasErrorState>>(
8288
base: T,

src/material/core/common-behaviors/initialized.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {Constructor} from './constructor';
1515
* If the subscription is made after it has already been marked as initialized, then it will trigger
1616
* an emit immediately.
1717
* @docs-private
18+
* @deprecated Will be removed together with `mixinInitializer`.
19+
* @breaking-change 19.0.0
1820
*/
1921
export interface HasInitialized {
2022
/** Stream that emits once during the directive/component's ngOnInit. */
@@ -30,7 +32,11 @@ export interface HasInitialized {
3032

3133
type HasInitializedCtor = Constructor<HasInitialized>;
3234

33-
/** Mixin to augment a directive with an initialized property that will emits when ngOnInit ends. */
35+
/**
36+
* Mixin to augment a directive with an initialized property that will emits when ngOnInit ends.
37+
* @deprecated Track the initialized state manually.
38+
* @breaking-change 19.0.0
39+
*/
3440
export function mixinInitialized<T extends Constructor<{}>>(base: T): HasInitializedCtor & T {
3541
return class extends base {
3642
/** Whether this directive has been marked as initialized. */

src/material/core/common-behaviors/tabindex.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {coerceNumberProperty} from '@angular/cdk/coercion';
1010
import {Constructor, AbstractConstructor} from './constructor';
1111
import {CanDisable} from './disabled';
1212

13-
/** @docs-private */
13+
/**
14+
* @docs-private
15+
* @deprecated Will be removed together with `mixinTabIndex`.
16+
* @breaking-change 19.0.0
17+
*/
1418
export interface HasTabIndex {
1519
/** Tabindex of the component. */
1620
tabIndex: number;
@@ -21,7 +25,11 @@ export interface HasTabIndex {
2125

2226
type HasTabIndexCtor = Constructor<HasTabIndex> & AbstractConstructor<HasTabIndex>;
2327

24-
/** Mixin to augment a directive with a `tabIndex` property. */
28+
/**
29+
* Mixin to augment a directive with a `tabIndex` property.
30+
* @deprecated Use an input with a transform instead.
31+
* @breaking-change 19.0.0
32+
*/
2533
export function mixinTabIndex<T extends AbstractConstructor<CanDisable>>(
2634
base: T,
2735
defaultTabIndex?: number,

tools/public_api_guard/cdk/table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export class HeaderRowOutlet implements RowOutlet {
496496
static ɵfac: i0.ɵɵFactoryDeclaration<HeaderRowOutlet, never>;
497497
}
498498

499-
// @public
499+
// @public @deprecated
500500
export function mixinHasStickyInput<T extends Constructor<{}>>(base: T): CanStickCtor & T;
501501

502502
// @public

tools/public_api_guard/material/core.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ export class AnimationDurations {
5353
static EXITING: string;
5454
}
5555

56-
// @public
56+
// @public @deprecated
5757
export interface CanColor {
5858
color: ThemePalette;
5959
defaultColor: ThemePalette | undefined;
6060
}
6161

62-
// @public
62+
// @public @deprecated
6363
export interface CanDisable {
6464
disabled: boolean;
6565
}
6666

67-
// @public
67+
// @public @deprecated
6868
export interface CanDisableRipple {
6969
disableRipple: boolean;
7070
}
7171

72-
// @public
72+
// @public @deprecated
7373
export interface CanUpdateErrorState {
7474
errorState: boolean;
7575
errorStateMatcher: ErrorStateMatcher_2;
@@ -157,13 +157,13 @@ export interface GranularSanityChecks {
157157
version: boolean;
158158
}
159159

160-
// @public
160+
// @public @deprecated
161161
export interface HasInitialized {
162162
initialized: Observable<void>;
163163
_markInitialized: () => void;
164164
}
165165

166-
// @public
166+
// @public @deprecated
167167
export interface HasTabIndex {
168168
defaultTabIndex: number;
169169
tabIndex: number;
@@ -431,22 +431,22 @@ export class MatRippleModule {
431431
static ɵmod: i0.ɵɵNgModuleDeclaration<MatRippleModule, never, [typeof i1_2.MatCommonModule, typeof i2.MatRipple], [typeof i2.MatRipple, typeof i1_2.MatCommonModule]>;
432432
}
433433

434-
// @public
434+
// @public @deprecated
435435
export function mixinColor<T extends _AbstractConstructor<HasElementRef>>(base: T, defaultColor?: ThemePalette): CanColorCtor & T;
436436

437-
// @public
437+
// @public @deprecated
438438
export function mixinDisabled<T extends _AbstractConstructor<{}>>(base: T): CanDisableCtor & T;
439439

440-
// @public
440+
// @public @deprecated
441441
export function mixinDisableRipple<T extends _AbstractConstructor<{}>>(base: T): CanDisableRippleCtor & T;
442442

443-
// @public
443+
// @public @deprecated
444444
export function mixinErrorState<T extends _AbstractConstructor<HasErrorState>>(base: T): CanUpdateErrorStateCtor & T;
445445

446-
// @public
446+
// @public @deprecated
447447
export function mixinInitialized<T extends _Constructor<{}>>(base: T): HasInitializedCtor & T;
448448

449-
// @public
449+
// @public @deprecated
450450
export function mixinTabIndex<T extends _AbstractConstructor<CanDisable>>(base: T, defaultTabIndex?: number): HasTabIndexCtor & T;
451451

452452
// @public

0 commit comments

Comments
 (0)