Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.8

- **Every component is OnPush.** None of the 35 components set a change detection strategy, so every one was checked on every pass. Each now uses `ChangeDetectionStrategy.OnPush`. Before switching, I audited each component for state that changes outside signals and template events, the kind OnPush stops rendering, and found none. The contact form's reset after sending is the closest call, and it now carries a comment saying why it still renders
- **A test keeps it that way.** `architecture.spec.ts` reads every `@Component` decorator with the TypeScript parser and fails, naming the class, on any component that doesn't choose OnPush or an explicit `Eager`. Using the parser rather than a text search means the code samples printed in the lessons don't count as components
- **Angular guide, lesson 09: change detection** (`/thoughts/angular-09-change-detection`). The live demo passes one object to an `Eager` child and an `OnPush` child: mutating it updates only the Eager one, replacing it updates both, and a signal reaches the OnPush child with no input change at all. The lesson covers zoneless scheduling, `markForCheck` vs `detectChanges`, NG0100, and the 21.2 rename of `Default` to `Eager`

## 2026-11-21 - version 1.4.7

- **fix: the contact form accepted blank messages.** `Validators.required` only rejects an empty string, so a name or message of nothing but spaces got through. Both now use a small `notBlank` validator in `shared/validators.ts`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.4.7",
"version": "1.4.8",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgComponentOutlet } from '@angular/common';
import { Component, effect, inject, viewChild } from '@angular/core';
import { ChangeDetectionStrategy, Component, effect, inject, viewChild } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { filter, map } from 'rxjs';
Expand All @@ -19,6 +19,7 @@ import { WindowManagerService } from './window-manager/window-manager.service';

@Component({
selector: 'app-root',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
RouterOutlet,
Desktop,
Expand Down
3 changes: 2 additions & 1 deletion src/app/apps/about-app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Component, output, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, output, signal } from '@angular/core';

export type AboutTab = 'overview' | 'skills' | 'experience';

@Component({
selector: 'app-about',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="about">
<div class="about-avatar">👤</div>
Expand Down
6 changes: 5 additions & 1 deletion src/app/apps/contact-app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, ElementRef, inject, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, ElementRef, inject, signal } from '@angular/core';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { notBlank } from '../shared/validators';

type SubmissionStatus = 'idle' | 'pending' | 'success' | 'error';

@Component({
selector: 'app-contact',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ReactiveFormsModule],
template: `
<div class="contact">
Expand Down Expand Up @@ -249,6 +250,9 @@ export class ContactApp {
this.submissionStatus.set('pending');

// Simulate async submission
// [ng-09 change detection] form.reset() changes plain control state,
// which marks nothing for check. It renders because the signal write next
// to it does. Drop that write and the old errors stay on screen.
setTimeout(() => {
this.submissionStatus.set('success');
this.form.reset();
Expand Down
10 changes: 9 additions & 1 deletion src/app/apps/finder/finder-app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Component, computed, inject, output, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
computed,
inject,
output,
signal,
} from '@angular/core';
import { FileSystemService, FileEntry } from './file-system.service';

@Component({
selector: 'app-finder',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="finder">
<div class="finder-toolbar">
Expand Down
3 changes: 2 additions & 1 deletion src/app/apps/placeholder-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, input } from '@angular/core';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';

@Component({
selector: 'app-placeholder',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="placeholder">
<span class="placeholder-icon">{{ icon() }}</span>
Expand Down
10 changes: 9 additions & 1 deletion src/app/apps/projects-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Component, computed, inject, output, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
computed,
inject,
output,
signal,
} from '@angular/core';
import { ProjectsService } from './projects.service';

export interface GitHubRepo {
Expand All @@ -12,6 +19,7 @@ export interface GitHubRepo {

@Component({
selector: 'app-projects',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="projects">
<div class="projects-header">
Expand Down
3 changes: 2 additions & 1 deletion src/app/apps/readme-app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { AppLauncherService } from '../shared/app-launcher.service';

@Component({
selector: 'app-readme',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="readme">
<h1>README.md</h1>
Expand Down
3 changes: 2 additions & 1 deletion src/app/apps/settings/system-preferences.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, inject, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { SettingsService } from '../../shared/settings/settings.service';

type Pane = 'appearance' | 'dock' | 'general';
Expand All @@ -10,6 +10,7 @@ interface SidebarItem {

@Component({
selector: 'app-system-preferences',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="settings">
<nav class="settings-sidebar">
Expand Down
3 changes: 2 additions & 1 deletion src/app/apps/terminal-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, inject, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { CommandParserService } from './command-parser.service';

interface TerminalEntry {
Expand All @@ -8,6 +8,7 @@ interface TerminalEntry {

@Component({
selector: 'app-terminal',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="terminal">
<div class="terminal-history">
Expand Down
48 changes: 47 additions & 1 deletion src/app/architecture.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve, dirname, sep } from 'node:path';
import * as ts from 'typescript';

/**
* [ng-01 structure] Architecture fitness tests.
Expand All @@ -9,7 +10,7 @@ import { join, relative, resolve, dirname, sep } from 'node:path';
* feature folder is quietly a dependency of the whole app. These tests make the
* convention executable: break the rule and CI goes red with the file name.
*
* The layering this repo uses (see docs/angular-guide/01-project-structure.md):
* The layering this repo uses (lesson 01, /thoughts/angular-01-project-structure):
*
* shell app.ts, menu-bar/, dock/, desktop/, window-manager/, ...
* shared/ services and building blocks anyone may use
Expand Down Expand Up @@ -37,6 +38,28 @@ function staticRelativeImports(file: string): string[] {
return specifiers.map((match) => resolve(dirname(file), match[1]));
}

/**
* Real `@Component(...)` decorators on classes, read with the TypeScript
* parser. A text search also matches the code samples the lessons print.
*/
function componentDecorators(file: string): { file: string; className: string; metadata: string }[] {
const source = ts.createSourceFile(file, readFileSync(file, 'utf-8'), ts.ScriptTarget.Latest, true);
const found: { file: string; className: string; metadata: string }[] = [];
const visit = (node: ts.Node) => {
if (ts.isClassDeclaration(node)) {
for (const decorator of ts.getDecorators(node) ?? []) {
const call = decorator.expression;
if (ts.isCallExpression(call) && ts.isIdentifier(call.expression) && call.expression.text === 'Component') {
found.push({ file, className: node.name?.text ?? '(anonymous)', metadata: call.arguments[0]?.getText(source) ?? '' });
}
}
}
ts.forEachChild(node, visit);
};
visit(source);
return found;
}

const isInside = (file: string, folder: string) =>
relative(join(APP_ROOT, folder), file).split(sep)[0] !== '..';

Expand Down Expand Up @@ -70,4 +93,27 @@ describe('[ng-01] architecture', () => {
.map((file) => relative(APP_ROOT, file));
expect(withNgModule).toEqual([]);
});

// [ng-09 change detection] OnPush everywhere, unless a component says
// otherwise out loud. The check is per decorator, not per file, because a
// file can declare several components. Eager (the new name for Default) is
// allowed only when written explicitly, so it is always a visible decision
// rather than a forgotten line.
it('every component sets OnPush, or opts into Eager explicitly', () => {
const decorators = files.flatMap(componentDecorators);
const missing = decorators
.filter(({ metadata }) => !/changeDetection:\s*ChangeDetectionStrategy\.(OnPush|Eager)\b/.test(metadata))
.map(({ file, className }) => `${relative(APP_ROOT, file)} (${className})`);

expect(decorators.length).toBeGreaterThan(30);
expect(missing).toEqual([]);
});

it('the decorator finder skips @Component( inside code-sample strings', () => {
const lesson02 = join(APP_ROOT, 'thoughts-content/lessons/lesson-02-components.ts');
expect(componentDecorators(lesson02).map(({ className }) => className)).toEqual([
'DemoBadge',
'Lesson02Components',
]);
});
});
11 changes: 10 additions & 1 deletion src/app/context-menu/context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { DOCUMENT } from '@angular/common';
import { Component, DestroyRef, inject, input, output, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
inject,
input,
output,
signal,
} from '@angular/core';

export interface ContextMenuItem {
id: string;
Expand All @@ -20,6 +28,7 @@ export const DEFAULT_DESKTOP_MENU_ITEMS: ContextMenuItem[] = [

@Component({
selector: 'app-context-menu',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (visible()) {
<div class="context-menu" [style.left.px]="x()" [style.top.px]="y()">
Expand Down
3 changes: 2 additions & 1 deletion src/app/desktop-icons/desktop-icon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, input, output, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, input, output, signal } from '@angular/core';

@Component({
selector: 'app-desktop-icon',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
class="desktop-icon"
Expand Down
3 changes: 2 additions & 1 deletion src/app/desktop-icons/desktop-icons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, inject, signal, viewChildren } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject, signal, viewChildren } from '@angular/core';
import { AppLauncherService } from '../shared/app-launcher.service';
import { DockService } from '../shared/dock.service';
import { DesktopIconComponent } from './desktop-icon';
Expand All @@ -11,6 +11,7 @@ export interface DesktopIconData {

@Component({
selector: 'app-desktop-icons',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [DesktopIconComponent],
template: `
<div class="desktop-icons-grid">
Expand Down
3 changes: 2 additions & 1 deletion src/app/desktop/desktop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

@Component({
selector: 'app-desktop',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<div class="desktop-wallpaper" [style.background]="wallpaper()"></div>`,
styles: `
:host {
Expand Down
3 changes: 2 additions & 1 deletion src/app/dock/dock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, computed, inject, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
import { SettingsService } from '../shared/settings/settings.service';
import { AppLauncherService } from '../shared/app-launcher.service';
import { DockItem, DockService } from '../shared/dock.service';

@Component({
selector: 'app-dock',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './dock.html',
styleUrl: './dock.scss',
})
Expand Down
2 changes: 2 additions & 0 deletions src/app/menu-bar/menu-bar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
computed,
DestroyRef,
Expand All @@ -15,6 +16,7 @@ import { MenuBarItem, MenuBarService } from './menu-bar.service';

@Component({
selector: 'app-menu-bar',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './menu-bar.html',
styleUrl: './menu-bar.scss',
// The live clock differs between server render and client bootstrap; skip
Expand Down
3 changes: 2 additions & 1 deletion src/app/spotlight/spotlight.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, inject, output, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject, output, signal } from '@angular/core';
import { SearchService, SearchResultGroup } from '../shared/search.service';

@Component({
selector: 'app-spotlight',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './spotlight.html',
styleUrl: './spotlight.scss',
})
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/callout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, input } from '@angular/core';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';

export type CalloutKind = 'tip' | 'pitfall' | 'expert';

Expand All @@ -19,6 +19,7 @@ const LABELS: Record<CalloutKind, string> = {
*/
@Component({
selector: 'app-callout',
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
role: 'note',
'[class]': '"callout callout--" + kind()',
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/code-block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, input, output, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, input, output, signal } from '@angular/core';

/**
* A labelled, scrollable code sample for lesson pages.
Expand All @@ -13,6 +13,7 @@ import { Component, input, output, signal } from '@angular/core';
*/
@Component({
selector: 'app-code-block',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<figure class="code-block">
<figcaption class="code-block-bar">
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/interview-questions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, input } from '@angular/core';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';

export interface InterviewQuestion {
q: string;
Expand All @@ -12,6 +12,7 @@ export interface InterviewQuestion {
*/
@Component({
selector: 'app-interview-questions',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@for (item of questions(); track item.q) {
<details class="qa">
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-01-structure.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, computed, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
Expand Down Expand Up @@ -52,6 +52,7 @@ const LAYER_LABELS: Record<Layer, string> = {

@Component({
selector: 'app-lesson-01-structure',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, InterviewQuestions],
template: `
<app-lesson part="01">
Expand Down
Loading
Loading