From 9660d69a7a4ece26df5ef4f25f9a96a6cc8ea4b6 Mon Sep 17 00:00:00 2001 From: Enea Jahollari Date: Wed, 27 Nov 2024 12:22:01 +0100 Subject: [PATCH] docs(docs-infra): remove unused code (#58925) Removed unused code from docs infra PR Close #58925 --- adev/shared-docs/services/index.ts | 1 - .../services/inject-async.service.ts | 92 ------------------- .../table-of-contents-scroll-spy.service.ts | 21 +---- .../layout/navigation/navigation.component.ts | 2 - 4 files changed, 1 insertion(+), 115 deletions(-) delete mode 100644 adev/shared-docs/services/inject-async.service.ts diff --git a/adev/shared-docs/services/index.ts b/adev/shared-docs/services/index.ts index 0d08b34b0e6..04ebdcf8d75 100644 --- a/adev/shared-docs/services/index.ts +++ b/adev/shared-docs/services/index.ts @@ -10,4 +10,3 @@ export * from './navigation-state.service'; export {TOC_SKIP_CONTENT_MARKER, TableOfContentsLoader} from './table-of-contents-loader.service'; export {TableOfContentsScrollSpy} from './table-of-contents-scroll-spy.service'; export * from './search.service'; -export * from './inject-async.service'; diff --git a/adev/shared-docs/services/inject-async.service.ts b/adev/shared-docs/services/inject-async.service.ts deleted file mode 100644 index 88ca3a6787a..00000000000 --- a/adev/shared-docs/services/inject-async.service.ts +++ /dev/null @@ -1,92 +0,0 @@ -/*! - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -import { - DestroyRef, - ENVIRONMENT_INITIALIZER, - EnvironmentInjector, - Injectable, - Injector, - Provider, - ProviderToken, - Type, - createEnvironmentInjector, - inject, -} from '@angular/core'; - -/** - * Convience method for lazy loading an injection token. - */ -export async function injectAsync( - injector: Injector, - providerLoader: () => Promise>, -): Promise { - const injectImpl = injector.get(InjectAsyncImpl); - return injectImpl.get(injector, providerLoader); -} - -@Injectable({providedIn: 'root'}) -class InjectAsyncImpl { - private overrides = new WeakMap(); // no need to cleanup - override(type: Type, mock: Type) { - this.overrides.set(type, mock); - } - - async get(injector: Injector, providerLoader: () => Promise>): Promise { - const type = await providerLoader(); - - // Check if we have overrides, O(1), low overhead - if (this.overrides.has(type)) { - const override = this.overrides.get(type); - return new override(); - } - - if (!(injector instanceof EnvironmentInjector)) { - // this is the DestroyRef of the component - const destroyRef = injector.get(DestroyRef); - - // This is the parent injector of the injector we're creating - const environmentInjector = injector.get(EnvironmentInjector); - - // Creating an environment injector to destroy it afterwards - const newInjector = createEnvironmentInjector([type as Provider], environmentInjector); - - // Destroy the injector to trigger DestroyRef.onDestroy on our service - destroyRef.onDestroy(() => { - newInjector.destroy(); - }); - - // We want to create the new instance of our service with our new injector - injector = newInjector; - } - - return injector.get(type)!; - } -} - -/** - * Helper function to mock the lazy loaded module in `injectAsync` - * - * @usage - * TestBed.configureTestingModule({ - * providers: [ - * mockAsyncProvider(SandboxService, fakeSandboxService) - * ] - * }); - */ -export function mockAsyncProvider(type: Type, mock: Type) { - return [ - { - provide: ENVIRONMENT_INITIALIZER, - multi: true, - useValue: () => { - inject(InjectAsyncImpl).override(type, mock); - }, - }, - ]; -} diff --git a/adev/shared-docs/services/table-of-contents-scroll-spy.service.ts b/adev/shared-docs/services/table-of-contents-scroll-spy.service.ts index 040d0d7ee12..5f6b990eb4b 100644 --- a/adev/shared-docs/services/table-of-contents-scroll-spy.service.ts +++ b/adev/shared-docs/services/table-of-contents-scroll-spy.service.ts @@ -19,11 +19,9 @@ import {RESIZE_EVENT_DELAY} from '../constants/index'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import {auditTime, debounceTime, fromEvent, startWith} from 'rxjs'; import {WINDOW} from '../providers/index'; -import {shouldReduceMotion} from '../utils/index'; import {TableOfContentsLoader} from './table-of-contents-loader.service'; export const SCROLL_EVENT_DELAY = 20; -export const SCROLL_FINISH_DELAY = SCROLL_EVENT_DELAY * 2; @Injectable({providedIn: 'root'}) // The service is responsible for listening for scrolling and resizing, @@ -35,6 +33,7 @@ export class TableOfContentsScrollSpy { private readonly viewportScroller = inject(ViewportScroller); private readonly injector = inject(EnvironmentInjector); private contentSourceElement: HTMLElement | null = null; + private lastContentWidth = 0; activeItemId = signal(null); @@ -65,24 +64,6 @@ export class TableOfContentsScrollSpy { this.viewportScroller.scrollToPosition([0, 0]); } - scrollToSection(id: string): void { - if (shouldReduceMotion()) { - this.offsetToSection(id); - } else { - const section = this.document.getElementById(id); - section?.scrollIntoView({behavior: 'smooth', block: 'start'}); - // We don't want to set the active item here, it would mess up the animation - // The scroll event handler will handle it for us - } - } - - private offsetToSection(id: string): void { - const section = this.document.getElementById(id); - section?.scrollIntoView({block: 'start'}); - // Here we need to set the active item manually because scroll events might not be fired - this.activeItemId.set(id); - } - // After window resize, we should update top value of each table content item private setResizeEventHandlers(destroyRef: DestroyRef) { fromEvent(this.window, 'resize') diff --git a/adev/src/app/core/layout/navigation/navigation.component.ts b/adev/src/app/core/layout/navigation/navigation.component.ts index 06194fe9316..25bd56213a1 100644 --- a/adev/src/app/core/layout/navigation/navigation.component.ts +++ b/adev/src/app/core/layout/navigation/navigation.component.ts @@ -20,7 +20,6 @@ import {takeUntilDestroyed, toObservable} from '@angular/core/rxjs-interop'; import { ClickOutside, NavigationState, - WINDOW, IconComponent, getBaseUrlAfterRedirects, isApple, @@ -56,7 +55,6 @@ export class Navigation implements OnInit { private readonly location = inject(Location); private readonly themeManager = inject(ThemeManager); private readonly isSearchDialogOpen = inject(IS_SEARCH_DIALOG_OPEN); - private readonly window = inject(WINDOW); private readonly versionManager = inject(VersionManager); readonly DOCS_ROUTE = PagePrefix.DOCS;