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 committed May 4, 2024
1 parent 6e1e70d commit ac2b72c
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 99 deletions.
3 changes: 1 addition & 2 deletions adev/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ APPLICATION_DEPS = [
"@npm//@lezer/javascript",
"@npm//@lezer/common",
"@npm//@xterm/xterm",
"@npm//@xterm/addon-fit",
"@npm//algoliasearch",
"@npm//xterm",
"@npm//xterm-addon-fit",
"@npm//angular-split",
"@npm//zone.js",
]
Expand Down
7 changes: 6 additions & 1 deletion adev/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
"builder": "@angular/build: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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion adev/src/app/editor/terminal/terminal.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SASS imports, here we're importing a CSS asset
//
// stylelint-disable-next-line @angular/no-import
@import 'xterm/css/xterm.css';
@import '@xterm/xterm/css/xterm.css';

.docs-tutorial-terminal {
display: block;
Expand Down
8 changes: 2 additions & 6 deletions adev/src/app/features/home/home.component.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"@types/shelljs": "^0.8.6",
"@types/systemjs": "6.13.5",
"@types/yargs": "^17.0.3",
"@xterm/addon-fit": "^0.10.0",
"algoliasearch": "^4.23.3",
"angular-1.5": "npm:angular@1.5",
"angular-1.6": "npm:angular@1.6",
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4208,6 +4208,7 @@
"@types/node" "*"

"@types/selenium-webdriver4@npm:@types/selenium-webdriver@4.1.22", "@types/selenium-webdriver@^4.1.21":
name "@types/selenium-webdriver4"
version "4.1.22"
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-4.1.22.tgz#344519b90727eb713e1ce6d2e0198eb0b4f8f316"
integrity sha512-MCL4l7q8dwxejr2Q2NXLyNwHWMPdlWE0Kpn6fFwJtvkJF7PTkG5jkvbH/X1IAAQxgt/L1dA8u2GtDeekvSKvOA==
Expand Down Expand Up @@ -4543,6 +4544,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.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@xterm/xterm/-/xterm-5.5.0.tgz#275fb8f6e14afa6e8a0c05d4ebc94523ff775396"
Expand Down

0 comments on commit ac2b72c

Please sign in to comment.