Skip to content

Commit facd027

Browse files
committed
refactor(material/sort): remove TypeScript mixin usages
Replaces the final usage of TypeScript mixins in the sort header.
1 parent e13ece1 commit facd027

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/material/sort/sort.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919
Output,
2020
booleanAttribute,
2121
} from '@angular/core';
22-
import {HasInitialized, mixinInitialized} from '@angular/material/core';
23-
import {Subject} from 'rxjs';
22+
import {Observable, ReplaySubject, Subject} from 'rxjs';
2423
import {SortDirection} from './sort-direction';
2524
import {
2625
getSortDuplicateSortableIdError,
@@ -65,10 +64,6 @@ export const MAT_SORT_DEFAULT_OPTIONS = new InjectionToken<MatSortDefaultOptions
6564
'MAT_SORT_DEFAULT_OPTIONS',
6665
);
6766

68-
// Boilerplate for applying mixins to MatSort.
69-
/** @docs-private */
70-
const _MatSortBase = mixinInitialized(class {});
71-
7267
/** Container for MatSortables to manage the sort state and provide default sort parameters. */
7368
@Directive({
7469
selector: '[matSort]',
@@ -78,7 +73,9 @@ const _MatSortBase = mixinInitialized(class {});
7873
},
7974
standalone: true,
8075
})
81-
export class MatSort extends _MatSortBase implements HasInitialized, OnChanges, OnDestroy, OnInit {
76+
export class MatSort implements OnChanges, OnDestroy, OnInit {
77+
private _initializedStream = new ReplaySubject<void>(1);
78+
8279
/** Collection of all registered sortables that this directive manages. */
8380
sortables = new Map<string, MatSortable>();
8481

@@ -126,13 +123,14 @@ export class MatSort extends _MatSortBase implements HasInitialized, OnChanges,
126123
/** Event emitted when the user changes either the active sort or sort direction. */
127124
@Output('matSortChange') readonly sortChange: EventEmitter<Sort> = new EventEmitter<Sort>();
128125

126+
/** Emits when the paginator is initialized. */
127+
initialized: Observable<void> = this._initializedStream;
128+
129129
constructor(
130130
@Optional()
131131
@Inject(MAT_SORT_DEFAULT_OPTIONS)
132132
private _defaultOptions?: MatSortDefaultOptions,
133-
) {
134-
super();
135-
}
133+
) {}
136134

137135
/**
138136
* Register function to be used by the contained MatSortables. Adds the MatSortable to the
@@ -192,7 +190,7 @@ export class MatSort extends _MatSortBase implements HasInitialized, OnChanges,
192190
}
193191

194192
ngOnInit() {
195-
this._markInitialized();
193+
this._initializedStream.next();
196194
}
197195

198196
ngOnChanges() {
@@ -201,6 +199,7 @@ export class MatSort extends _MatSortBase implements HasInitialized, OnChanges,
201199

202200
ngOnDestroy() {
203201
this._stateChanges.complete();
202+
this._initializedStream.complete();
204203
}
205204
}
206205

tools/public_api_guard/material/sort.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { ChangeDetectorRef } from '@angular/core';
1111
import { ElementRef } from '@angular/core';
1212
import { EventEmitter } from '@angular/core';
1313
import { FocusMonitor } from '@angular/cdk/a11y';
14-
import { HasInitialized } from '@angular/material/core';
1514
import * as i0 from '@angular/core';
1615
import * as i1 from '@angular/material/core';
1716
import { InjectionToken } from '@angular/core';
17+
import { Observable } from 'rxjs';
1818
import { OnChanges } from '@angular/core';
1919
import { OnDestroy } from '@angular/core';
2020
import { OnInit } from '@angular/core';
@@ -46,7 +46,7 @@ export const MAT_SORT_HEADER_INTL_PROVIDER: {
4646
export function MAT_SORT_HEADER_INTL_PROVIDER_FACTORY(parentIntl: MatSortHeaderIntl): MatSortHeaderIntl;
4747

4848
// @public
49-
export class MatSort extends _MatSortBase implements HasInitialized, OnChanges, OnDestroy, OnInit {
49+
export class MatSort implements OnChanges, OnDestroy, OnInit {
5050
constructor(_defaultOptions?: MatSortDefaultOptions | undefined);
5151
active: string;
5252
deregister(sortable: MatSortable): void;
@@ -55,6 +55,7 @@ export class MatSort extends _MatSortBase implements HasInitialized, OnChanges,
5555
disableClear: boolean;
5656
disabled: boolean;
5757
getNextSortDirection(sortable: MatSortable): SortDirection;
58+
initialized: Observable<void>;
5859
// (undocumented)
5960
static ngAcceptInputType_disableClear: unknown;
6061
// (undocumented)

0 commit comments

Comments
 (0)