Skip to content

Commit

Permalink
refactor(youtube-player): switch to inject function (#29775)
Browse files Browse the repository at this point in the history
Reworks the `youtube-player` to use the `inject` function instead of constructor-based injection.
  • Loading branch information
crisbeto authored Sep 24, 2024
1 parent 7c9bf99 commit 2857b73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
Output,
ViewChild,
ViewEncapsulation,
Inject,
PLATFORM_ID,
OnChanges,
SimpleChanges,
Expand Down Expand Up @@ -131,19 +130,21 @@ enum PlayerState {
`,
})
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
/** Whether we're currently rendering inside a browser. */
private readonly _isBrowser: boolean;
private _ngZone = inject(NgZone);
private readonly _nonce = inject(CSP_NONCE, {optional: true});
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
private _player: YT.Player | undefined;
private _pendingPlayer: YT.Player | undefined;
private _existingApiReadyCallback: (() => void) | undefined;
private _pendingPlayerState: PendingPlayerState | undefined;
private readonly _destroyed = new Subject<void>();
private readonly _playerChanges = new BehaviorSubject<YT.Player | undefined>(undefined);
private readonly _nonce = inject(CSP_NONCE, {optional: true});
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
protected _isLoading = false;
protected _hasPlaceholder = true;

/** Whether we're currently rendering inside a browser. */
private readonly _isBrowser: boolean;

/** YouTube Video ID to view */
@Input()
videoId: string | undefined;
Expand Down Expand Up @@ -241,10 +242,10 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
@ViewChild('youtubeContainer', {static: true})
youtubeContainer: ElementRef<HTMLElement>;

constructor(
private _ngZone: NgZone,
@Inject(PLATFORM_ID) platformId: Object,
) {
constructor(...args: unknown[]);

constructor() {
const platformId = inject<Object>(PLATFORM_ID);
const config = inject(YOUTUBE_PLAYER_CONFIG, {optional: true});
this.loadApi = config?.loadApi ?? true;
this.disablePlaceholder = !!config?.disablePlaceholder;
Expand Down
3 changes: 1 addition & 2 deletions tools/public_api_guard/youtube-player/youtube-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AfterViewInit } from '@angular/core';
import { ElementRef } from '@angular/core';
import * as i0 from '@angular/core';
import { InjectionToken } from '@angular/core';
import { NgZone } from '@angular/core';
import { Observable } from 'rxjs';
import { OnChanges } from '@angular/core';
import { OnDestroy } from '@angular/core';
Expand All @@ -24,7 +23,7 @@ export const YOUTUBE_PLAYER_CONFIG: InjectionToken<YouTubePlayerConfig>;

// @public
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
constructor(_ngZone: NgZone, platformId: Object);
constructor(...args: unknown[]);
// (undocumented)
readonly apiChange: Observable<YT.PlayerEvent>;
disableCookies: boolean;
Expand Down

0 comments on commit 2857b73

Please sign in to comment.