
☦️, husband, father, Angular dev, RxJS courses author (https://nitter.cf/t.co/N1V9ThF2Ln, https://nitter.cf/t.co/Ypb0qKtLFi),Angular mentor, @indepth_dev writer, https://nitter.cf/t.co/hPYTpW0EqG
- Tweets3.3K
- Following627
- Followers906
- Likes7.8K

ALT Angular code in telemetry.ts. A @Service() class Telemetry with private readonly http = inject(HttpClient). Its constructor adds a window 'pagehide' listener that calls this.send('page_leave', location.pathname). Its send(event: string, data: unknown) method calls this.http.post('/api/telemetry', { event, data }, { keepalive: true }).subscribe(). Next, class CrashReporter implements ErrorHandler, with private readonly telemetry = inject(Telemetry) and handleError(error: unknown) that calls console.error(error) and this.telemetry.send('crash', String(error)). Last, export const appConfig: ApplicationConfig with providers provideHttpClient(withFetch()) and { provide: ErrorHandler, useClass: CrashReporter }. The keepalive line and the withFetch line are highlighted.
![JavaScript code in folder.js. A class Folder has a constructor(name, children = []) that stores this.name and this.children. It has a generator method *[Symbol.iterator]() (highlighted) that does yield this; then, for (const child of this.children), yield* child. Usage: const src = new Folder('src', [new Folder('app', [new Folder('pages')]), new Folder('assets')]). Then [...src].map((folder) => folder.name) gives ['src', 'app', 'pages', 'assets'].](https://pbs.twimg.com/media/HWR4fanWcAA5L0P.jpg?name=small&format=webp)
ALT JavaScript code in folder.js. A class Folder has a constructor(name, children = []) that stores this.name and this.children. It has a generator method *[Symbol.iterator]() (highlighted) that does yield this; then, for (const child of this.children), yield* child. Usage: const src = new Folder('src', [new Folder('app', [new Folder('pages')]), new Folder('assets')]). Then [...src].map((folder) => folder.name) gives ['src', 'app', 'pages', 'assets'].

ALT Angular code in a dark editor, with line 7 highlighted: // the only part of the SDK the app is allowed to use export abstract class Analytics { abstract track(event: string, props?: Record<string, unknown>): void; } // app.config.ts: point the token at the vendor singleton { provide: Analytics, useExisting: SegmentAnalytics }, // checkout.ts private readonly analytics = inject(Analytics); // only .track() exists here

ALT if (signal) signal.addEventListener('abort', () => controller.abort()); const timeout = setTimeout(() => controller.abort(), ms); // Avoid creating a closure over `this`, `init`, or `options` to prevent memory leaks. // An arrow function like `() => controller.abort()` captures the surrounding scope, // which includes the request body and other large objects. When the user passes a // long-lived AbortSignal, the listener prevents those objects from being GC'd for // the lifetime of the signal. Using `.bind()` only retains a reference to the // controller itself. const abort = controller.abort.bind(controller); if (signal) signal.addEventListener('abort', abort, { once: true }); const timeout = setTimeout(abort, ms);



















