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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

## 2026-11-21 - version 1.4.9

- **Every lesson has an "On this page" nav.** It sticks to the top while you read, jumps to a section (moving focus to its heading), and highlights the section in view with `aria-current="location"`. Smooth scrolling switches off under `prefers-reduced-motion`. The lessons had grown long enough that I kept losing my place in them
- **Two directives build it.** `LessonSection` matches every `h2` in a lesson, gives it an id from its text and registers it with `ScrollSpy`, which watches the registered headings with an `IntersectionObserver` created only in the browser. The lesson component takes `ScrollSpy` as a host directive, so no lesson has to remember an attribute. The nav and the heading ids are both in the prerendered HTML
- **Angular guide, lesson 10: directives** (`/thoughts/angular-10-directives`). The live demos are a structural directive built on `TemplateRef` and `ViewContainerRef`, and an attribute directive composed into a component with `hostDirectives` and a renamed input. The lesson walks through the nav's own code
- **Initial bundle 392.64 → 394.56 kB.** All the new code is lazy, but this is the first use of `contentChildren`, `hostDirectives` and `afterNextRender`, and their runtime lives in the shared `@angular/core` chunk

## 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
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.8",
"version": "1.4.9",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ describe('app routes', () => {

expect(harness.routeDebugElement?.componentInstance).toBeInstanceOf(ThoughtsListComponent);
expect(titles.length).toBeGreaterThan(0);
expect(titles.every((title) => title.includes('Angular 0'))).toBe(true);
expect(titles.every((title) => /Angular \d{2}:/.test(title))).toBe(true);
});
});
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
Expand Up @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/c
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

export type Layer = 'shell' | 'shared' | 'feature' | 'other-feature';
Expand Down Expand Up @@ -53,7 +54,7 @@ const LAYER_LABELS: Record<Layer, string> = {
@Component({
selector: 'app-lesson-01-structure',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, InterviewQuestions],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, InterviewQuestions],
template: `
<app-lesson part="01">

Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-02-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

type Tone = 'info' | 'warn';
Expand Down Expand Up @@ -72,7 +73,7 @@ export class DemoBadge {
@Component({
selector: 'app-lesson-02-components',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions, DemoBadge],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions, DemoBadge],
template: `
<app-lesson part="02">
<h2>Simple</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-03-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

const STARTING_TAGS = ['signals', 'pipes', 'control-flow'];

@Component({
selector: 'app-lesson-03-templates',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions],
template: `
<app-lesson part="03">
<h2>Simple</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-04-signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

const UNIT_PRICE = 12;
Expand All @@ -16,7 +17,7 @@ const SHIPPING: Record<Country, string[]> = {
@Component({
selector: 'app-lesson-04-signals',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions],
template: `
<app-lesson part="04">
<h2>Simple</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-05-di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ export class TallyButton {
@Component({
selector: 'app-lesson-05-di',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions, TallyScope, TallyButton],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions, TallyScope, TallyButton],
providers: [TallyNumbering],
template: `
<app-lesson part="05">
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-06-rxjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';
import { searchAsYouType, SearchStrategy } from './search-race';

Expand All @@ -30,7 +31,7 @@ function slowSearch(query: string): Observable<SearchResult> {
@Component({
selector: 'app-lesson-06-rxjs',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions],
template: `
<app-lesson part="06">
<h2>Simple</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-07-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';
import { firstMatch } from './route-match';

Expand All @@ -14,7 +15,7 @@ const entries = (record: Record<string, unknown>) =>
@Component({
selector: 'app-lesson-07-routing',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions],
template: `
<app-lesson part="07">
<h2>Simple</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/app/thoughts-content/lessons/lesson-08-forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

/**
Expand All @@ -19,7 +20,7 @@ const matchingPasswords: ValidatorFn = (group): ValidationErrors | null => {
@Component({
selector: 'app-lesson-08-forms',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Lesson, LessonDemo, CodeBlock, Callout, InterviewQuestions, ReactiveFormsModule],
imports: [Lesson,LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions, ReactiveFormsModule],
template: `
<app-lesson part="08">
<h2>Simple</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Callout } from './callout';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonSection } from './lesson-section';
import { LessonDemo } from './lesson-demo';

interface Profile {
Expand Down Expand Up @@ -63,6 +64,7 @@ export class OnPushProfileCard {
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
Lesson,
LessonSection,
LessonDemo,
CodeBlock,
Callout,
Expand Down
55 changes: 55 additions & 0 deletions src/app/thoughts-content/lessons/lesson-10-directives.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import * as axeMatchers from 'vitest-axe/matchers';
import { axe } from '../../../test/a11y';
import { LESSON_PAGES } from './lessons';
import { Lesson10Directives } from './lesson-10-directives';

expect.extend(axeMatchers);

describe('Lesson10Directives', () => {
let fixture: ComponentFixture<Lesson10Directives>;
let el: HTMLElement;

beforeEach(async () => {
await TestBed.configureTestingModule({ imports: [Lesson10Directives] }).compileComponents();
fixture = TestBed.createComponent(Lesson10Directives);
await fixture.whenStable();
el = fixture.nativeElement as HTMLElement;
});

it('is registered as the lesson page for its thought', () => {
expect(LESSON_PAGES['angular-10-directives']).toBeDefined();
});

it('teaches at three levels, then pitfalls and interview questions', () => {
const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim());
expect(headings).toEqual(
expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']),
);
});

it('a custom structural directive adds and removes its template', async () => {
expect(el.querySelector('#demo-unless-content')).not.toBeNull();

el.querySelector<HTMLButtonElement>('#demo-unless-toggle')!.click();
await fixture.whenStable();
expect(el.querySelector('#demo-unless-content')).toBeNull();

el.querySelector<HTMLButtonElement>('#demo-unless-toggle')!.click();
await fixture.whenStable();
expect(el.querySelector('#demo-unless-content')).not.toBeNull();
});

it('a host directive styles the component it is composed into, through an aliased input', async () => {
const select = el.querySelector<HTMLSelectElement>('#demo-chip-color')!;
select.value = 'gold';
select.dispatchEvent(new Event('change'));
await fixture.whenStable();

expect(el.querySelector<HTMLElement>('#demo-chip')!.style.backgroundColor).toBe('gold');
});

it('has no axe violations', async () => {
expect(await axe(el)).toHaveNoViolations();
});
});
Loading
Loading