Skip to content

Commit

Permalink
refactor(material/sort): remove TypeScript mixin usages
Browse files Browse the repository at this point in the history
Replaces the final usage of TypeScript mixins in the sort header.
  • Loading branch information
crisbeto committed Feb 15, 2024
1 parent e13ece1 commit facd027
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
21 changes: 10 additions & 11 deletions src/material/sort/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {
Output,
booleanAttribute,
} from '@angular/core';
import {HasInitialized, mixinInitialized} from '@angular/material/core';
import {Subject} from 'rxjs';
import {Observable, ReplaySubject, Subject} from 'rxjs';
import {SortDirection} from './sort-direction';
import {
getSortDuplicateSortableIdError,
Expand Down Expand Up @@ -65,10 +64,6 @@ export const MAT_SORT_DEFAULT_OPTIONS = new InjectionToken<MatSortDefaultOptions
'MAT_SORT_DEFAULT_OPTIONS',
);

// Boilerplate for applying mixins to MatSort.
/** @docs-private */
const _MatSortBase = mixinInitialized(class {});

/** Container for MatSortables to manage the sort state and provide default sort parameters. */
@Directive({
selector: '[matSort]',
Expand All @@ -78,7 +73,9 @@ const _MatSortBase = mixinInitialized(class {});
},
standalone: true,
})
export class MatSort extends _MatSortBase implements HasInitialized, OnChanges, OnDestroy, OnInit {
export class MatSort implements OnChanges, OnDestroy, OnInit {
private _initializedStream = new ReplaySubject<void>(1);

/** Collection of all registered sortables that this directive manages. */
sortables = new Map<string, MatSortable>();

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

/** Emits when the paginator is initialized. */
initialized: Observable<void> = this._initializedStream;

constructor(
@Optional()
@Inject(MAT_SORT_DEFAULT_OPTIONS)
private _defaultOptions?: MatSortDefaultOptions,
) {
super();
}
) {}

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

ngOnInit() {
this._markInitialized();
this._initializedStream.next();
}

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

ngOnDestroy() {
this._stateChanges.complete();
this._initializedStream.complete();
}
}

Expand Down
5 changes: 3 additions & 2 deletions tools/public_api_guard/material/sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { ChangeDetectorRef } from '@angular/core';
import { ElementRef } from '@angular/core';
import { EventEmitter } from '@angular/core';
import { FocusMonitor } from '@angular/cdk/a11y';
import { HasInitialized } from '@angular/material/core';
import * as i0 from '@angular/core';
import * as i1 from '@angular/material/core';
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';
import { OnChanges } from '@angular/core';
import { OnDestroy } from '@angular/core';
import { OnInit } from '@angular/core';
Expand Down Expand Up @@ -46,7 +46,7 @@ export const MAT_SORT_HEADER_INTL_PROVIDER: {
export function MAT_SORT_HEADER_INTL_PROVIDER_FACTORY(parentIntl: MatSortHeaderIntl): MatSortHeaderIntl;

// @public
export class MatSort extends _MatSortBase implements HasInitialized, OnChanges, OnDestroy, OnInit {
export class MatSort implements OnChanges, OnDestroy, OnInit {
constructor(_defaultOptions?: MatSortDefaultOptions | undefined);
active: string;
deregister(sortable: MatSortable): void;
Expand All @@ -55,6 +55,7 @@ export class MatSort extends _MatSortBase implements HasInitialized, OnChanges,
disableClear: boolean;
disabled: boolean;
getNextSortDirection(sortable: MatSortable): SortDirection;
initialized: Observable<void>;
// (undocumented)
static ngAcceptInputType_disableClear: unknown;
// (undocumented)
Expand Down

0 comments on commit facd027

Please sign in to comment.