mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs(docs-infra): remove unused code (#58925)
Removed unused code from docs infra PR Close #58925
This commit is contained in:
parent
c64f0d86f8
commit
9660d69a7a
4 changed files with 1 additions and 115 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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<T>(
|
||||
injector: Injector,
|
||||
providerLoader: () => Promise<ProviderToken<T>>,
|
||||
): Promise<T> {
|
||||
const injectImpl = injector.get(InjectAsyncImpl);
|
||||
return injectImpl.get(injector, providerLoader);
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
class InjectAsyncImpl<T> {
|
||||
private overrides = new WeakMap(); // no need to cleanup
|
||||
override<T>(type: Type<T>, mock: Type<unknown>) {
|
||||
this.overrides.set(type, mock);
|
||||
}
|
||||
|
||||
async get(injector: Injector, providerLoader: () => Promise<ProviderToken<T>>): Promise<T> {
|
||||
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<T>(type: Type<T>, mock: Type<unknown>) {
|
||||
return [
|
||||
{
|
||||
provide: ENVIRONMENT_INITIALIZER,
|
||||
multi: true,
|
||||
useValue: () => {
|
||||
inject(InjectAsyncImpl).override(type, mock);
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -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<string | null>(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')
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue