Skip to content

Commit

Permalink
docs(docs-infra): Go zoneless and enable the zoneless scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMeche authored and atscott committed Apr 30, 2024
1 parent 3312727 commit 144d6d6
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 100 deletions.
2 changes: 1 addition & 1 deletion adev/BUILD.bazel
Expand Up @@ -78,7 +78,7 @@ APPLICATION_DEPS = [
"@npm//@lezer/javascript",
"@npm//@lezer/common",
"@npm//@xterm/xterm",
"@npm//xterm-addon-fit",
"@npm//@xterm/addon-fit",
"@npm//angular-split",
]

Expand Down
7 changes: 6 additions & 1 deletion adev/angular.json
Expand Up @@ -20,11 +20,16 @@
"builder": "@angular-devkit/build-angular:application",
"options": {
"externalDependencies": ["path"],
"define": {
// Until this is merged https://github.com/xtermjs/xterm.js/issues/5030
"self": "this"
},
"outputPath": "dist/angular-dev",
"index": "src/index.html",
"browser": "src/main.ts",
"server": "src/main.server.ts",
"polyfills": ["src/polyfills.ts", "zone.js"],
"ssr": true,
"polyfills": [],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": ["src/favicon.ico", "src/robots.txt", "src/assets"],
Expand Down
35 changes: 10 additions & 25 deletions adev/src/app/app.component.ts
Expand Up @@ -7,15 +7,7 @@
*/

import {DOCUMENT, isPlatformBrowser} from '@angular/common';
import {
Component,
inject,
NgZone,
OnInit,
PLATFORM_ID,
signal,
WritableSignal,
} from '@angular/core';
import {Component, inject, OnInit, PLATFORM_ID, signal, WritableSignal} from '@angular/core';
import {NavigationEnd, NavigationSkipped, Router, RouterLink, RouterOutlet} from '@angular/router';
import {filter, map, skip} from 'rxjs/operators';
import {
Expand Down Expand Up @@ -49,7 +41,6 @@ import {ESCAPE, SEARCH_TRIGGER_KEY} from './core/constants/keys';
})
export class AppComponent implements OnInit {
private readonly document = inject(DOCUMENT);
private readonly ngZone = inject(NgZone);
private readonly router = inject(Router);
private readonly window = inject(WINDOW);

Expand Down Expand Up @@ -106,22 +97,16 @@ export class AppComponent implements OnInit {
}

private setSearchDialogVisibilityOnKeyPress(): void {
this.ngZone.runOutsideAngular(() => {
this.window.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.key === SEARCH_TRIGGER_KEY && (event.metaKey || event.ctrlKey)) {
this.ngZone.run(() => {
event.preventDefault();
this.displaySearchDialog.update((display) => !display);
});
}
this.window.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.key === SEARCH_TRIGGER_KEY && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
this.displaySearchDialog.update((display) => !display);
}

if (event.key === ESCAPE && this.displaySearchDialog()) {
this.ngZone.run(() => {
event.preventDefault();
this.displaySearchDialog.set(false);
});
}
});
if (event.key === ESCAPE && this.displaySearchDialog()) {
event.preventDefault();
this.displaySearchDialog.set(false);
}
});
}

Expand Down
3 changes: 2 additions & 1 deletion adev/src/app/app.config.ts
Expand Up @@ -14,6 +14,7 @@ import {
ErrorHandler,
inject,
provideZoneChangeDetection,
provideExperimentalZonelessChangeDetection,
} from '@angular/core';
import {
DOCS_CONTENT_LOADER,
Expand Down Expand Up @@ -68,6 +69,7 @@ export const appConfig: ApplicationConfig = {
},
}),
),
provideExperimentalZonelessChangeDetection(),
provideClientHydration(),
provideHttpClient(withFetch()),
provideAnimationsAsync(),
Expand All @@ -91,7 +93,6 @@ export const appConfig: ApplicationConfig = {
deps: [DOCUMENT],
},
{provide: TitleStrategy, useClass: ADevTitleStrategy},
provideZoneChangeDetection({eventCoalescing: true}),
ReferenceScrollHandler,
],
};
2 changes: 1 addition & 1 deletion adev/src/app/editor/terminal/terminal-handler.service.ts
Expand Up @@ -8,7 +8,7 @@

import {Injectable} from '@angular/core';
import {Terminal} from '@xterm/xterm';
import {FitAddon} from 'xterm-addon-fit';
import {FitAddon} from '@xterm/addon-fit';
import {InteractiveTerminal} from './interactive-terminal';

export enum TerminalType {
Expand Down
8 changes: 2 additions & 6 deletions adev/src/app/features/home/home.component.ts
Expand Up @@ -13,7 +13,6 @@ import {
Component,
ElementRef,
Injector,
NgZone,
OnDestroy,
OnInit,
PLATFORM_ID,
Expand Down Expand Up @@ -45,7 +44,6 @@ export default class Home implements OnInit, AfterViewInit, OnDestroy {

private readonly document = inject(DOCUMENT);
private readonly injector = inject(Injector);
private readonly ngZone = inject(NgZone);
private readonly platformId = inject(PLATFORM_ID);
private readonly window = inject(WINDOW);

Expand All @@ -63,7 +61,7 @@ export default class Home implements OnInit, AfterViewInit, OnDestroy {
}
}

ngAfterViewInit(): void {
ngAfterViewInit() {
this.element = this.home.nativeElement;

if (isPlatformBrowser(this.platformId)) {
Expand All @@ -75,9 +73,7 @@ export default class Home implements OnInit, AfterViewInit, OnDestroy {
this.initIntersectionObserver();

if (this.isWebGLAvailable() && !shouldReduceMotion()) {
this.ngZone.runOutsideAngular(async () => {
await this.loadHomeAnimation();
});
this.loadHomeAnimation();
}
}
}
Expand Down
Expand Up @@ -11,7 +11,6 @@ import {
DestroyRef,
EnvironmentInjector,
Injectable,
NgZone,
OnDestroy,
afterNextRender,
inject,
Expand Down Expand Up @@ -41,7 +40,6 @@ export class ReferenceScrollHandler implements OnDestroy, ReferenceScrollHandler
private readonly destroyRef = inject(DestroyRef);
private readonly document = inject(DOCUMENT);
private readonly injector = inject(EnvironmentInjector);
private readonly ngZone = inject(NgZone);
private readonly window = inject(WINDOW);

private readonly cardOffsetTop = new Map<string, number>();
Expand Down Expand Up @@ -75,35 +73,31 @@ export class ReferenceScrollHandler implements OnDestroy, ReferenceScrollHandler
return;
}

this.ngZone.runOutsideAngular(() => {
fromEvent(tocContainer, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event) => {
// Get the card member ID from the attributes
const target =
event.target instanceof HTMLButtonElement
? event.target
: this.findButtonElement(event.target as HTMLElement);
const memberId = this.getMemberId(target);

if (memberId) {
const card = this.document.querySelector<HTMLDivElement>(`#${memberId}`);
this.scrollToCard(card);
}
});
});
fromEvent(tocContainer, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event) => {
// Get the card member ID from the attributes
const target =
event.target instanceof HTMLButtonElement
? event.target
: this.findButtonElement(event.target as HTMLElement);
const memberId = this.getMemberId(target);

if (memberId) {
const card = this.document.querySelector<HTMLDivElement>(`#${memberId}`);
this.scrollToCard(card);
}
});
}

private setupMemberCardListeners(): void {
this.ngZone.runOutsideAngular(() => {
this.getAllMemberCards().forEach((card) => {
this.cardOffsetTop.set(card.id, card.offsetTop);
fromEvent(card, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.scrollToCard(card);
});
});
this.getAllMemberCards().forEach((card) => {
this.cardOffsetTop.set(card.id, card.offsetTop);
fromEvent(card, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.scrollToCard(card);
});
});
}

Expand All @@ -113,9 +107,7 @@ export class ReferenceScrollHandler implements OnDestroy, ReferenceScrollHandler
takeUntilDestroyed(this.destroyRef),
);

this.ngZone.runOutsideAngular(() => {
scroll$.subscribe(() => this.setActiveCodeLine());
});
scroll$.subscribe(() => this.setActiveCodeLine());
}

private listenToResizeCardContainer(): void {
Expand Down Expand Up @@ -209,12 +201,10 @@ export class ReferenceScrollHandler implements OnDestroy, ReferenceScrollHandler
this.resizeObserver?.disconnect();

this.resizeObserver = new ResizeObserver((_) => {
this.ngZone.run(() => {
const offsetTop = tabBody.getBoundingClientRect().top;
if (offsetTop) {
this.membersMarginTopInPx.set(offsetTop);
}
});
const offsetTop = tabBody.getBoundingClientRect().top;
if (offsetTop) {
this.membersMarginTopInPx.set(offsetTop);
}
});

this.resizeObserver.observe(tabBody);
Expand Down
13 changes: 5 additions & 8 deletions adev/src/app/features/tutorial/split-resizer-handler.service.ts
Expand Up @@ -8,7 +8,7 @@

import {FocusMonitor} from '@angular/cdk/a11y';
import {DOCUMENT} from '@angular/common';
import {DestroyRef, ElementRef, Injectable, NgZone, inject, signal} from '@angular/core';
import {DestroyRef, ElementRef, Injectable, inject, signal} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {fromEvent, combineLatest} from 'rxjs';
import {map, filter} from 'rxjs/operators';
Expand All @@ -33,7 +33,6 @@ export class SplitResizerHandler {
private readonly destroyRef = inject(DestroyRef);
private readonly document = inject(DOCUMENT);
private readonly focusMonitor = inject(FocusMonitor);
private readonly ngZone = inject(NgZone);

private container!: ElementRef<any>;
private content!: ElementRef<HTMLDivElement>;
Expand Down Expand Up @@ -151,13 +150,11 @@ export class SplitResizerHandler {
takeUntilDestroyed(this.destroyRef),
)
.subscribe(([_, keyEvent]) => {
this.ngZone.run(() => {
const shift = keyEvent.key === 'ArrowLeft' ? -1 : 1;
const shift = keyEvent.key === 'ArrowLeft' ? -1 : 1;

const contentWidth = this.getCurrentContainerWidth(this.content.nativeElement);
const editorWidth = this.getCurrentContainerWidth(this.editor!.nativeElement);
this.setWidthOfTheContainers(contentWidth + shift, editorWidth - shift);
});
const contentWidth = this.getCurrentContainerWidth(this.content.nativeElement);
const editorWidth = this.getCurrentContainerWidth(this.editor!.nativeElement);
this.setWidthOfTheContainers(contentWidth + shift, editorWidth - shift);
});
}

Expand Down
16 changes: 0 additions & 16 deletions adev/src/polyfills.ts

This file was deleted.

2 changes: 1 addition & 1 deletion adev/tsconfig.app.json
Expand Up @@ -5,6 +5,6 @@
"outDir": "../../out-tsc/app",
"types": ["node"]
},
"files": ["src/main.ts", "src/main.server.ts", "src/polyfills.ts"],
"files": ["src/main.ts", "src/main.server.ts"],
"include": ["src/**/*.d.ts", "../../node_modules/@types/dom-navigation/index.d.ts"]
}
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -91,6 +91,7 @@
"@types/shelljs": "^0.8.6",
"@types/systemjs": "6.13.5",
"@types/yargs": "^17.0.3",
"@xterm/addon-fit": "^0.10.0",
"angular-1.5": "npm:angular@1.5",
"angular-1.6": "npm:angular@1.6",
"angular-1.7": "npm:angular@1.7",
Expand Down Expand Up @@ -183,6 +184,7 @@
"@types/inquirer": "^9.0.3",
"@types/jsdom": "^21.1.5",
"@typescript/vfs": "^1.5.0",
"@xterm/xterm": "^5.4.0",
"@yarnpkg/lockfile": "^1.1.0",
"adm-zip": "^0.5.10",
"angular-split": "^17.1.1",
Expand Down Expand Up @@ -218,9 +220,7 @@
"tslint-no-toplevel-property-access": "0.0.2",
"typed-graphqlify": "^3.1.1",
"vrsource-tslint-rules": "6.0.0",
"xregexp": "^5.1.1",
"@xterm/xterm": "^5.4.0",
"xterm-addon-fit": "^0.8.0"
"xregexp": "^5.1.1"
},
"// 3": "Ensure that transitive dependencies on `https-proxy-agent` are at minimum v5 as older versions patch NodeJS directly, breaking tools like webdriver which is used by the karma-sauce-launcher as an example.",
"// 4": "Ensure that a single instance of the `saucelabs` package is used. Protractor and the Karma sauce launcher pull this package as dependency. A single instance allows for e.g. easier patching in the Karma config.",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -4982,6 +4982,11 @@
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz#a1337ca426aa61cef9fe15b5b28e340a72f6fa99"
integrity sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw==

"@xterm/addon-fit@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@xterm/addon-fit/-/addon-fit-0.10.0.tgz#bebf87fadd74e3af30fdcdeef47030e2592c6f55"
integrity sha512-UFYkDm4HUahf2lnEyHvio51TNGiLK66mqP2JoATy7hRZeXaGMRDr00JiSF7m63vR5WKATF605yEggJKsw0JpMQ==

"@xterm/xterm@^5.4.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@xterm/xterm/-/xterm-5.5.0.tgz#275fb8f6e14afa6e8a0c05d4ebc94523ff775396"
Expand Down

0 comments on commit 144d6d6

Please sign in to comment.