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

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

## 2026-11-21 - version 1.4.3

- **Series navigation in the reader**: every Angular guide lesson ends with "Part N of M" and links to the previous and next lessons. They're real `routerLink` anchors, so they prerender as `href`s and ⌘-click opens a new tab
- **fix: the reader went stale on reuse.** `thought-detail.ts` read `route.snapshot` once, and the router reuses the component when only `:slug` changes, so Next would have kept showing the lesson you were on. The slug is now a signal (`toSignal(route.paramMap)`), and the thought, series position and lazy lesson page are all `computed()`/`resource()` off it. The reader also scrolls back to the top when the slug changes
- The reader specs now drive the real router through `RouterTestingHarness` instead of mocking `ActivatedRoute.snapshot`. A snapshot mock can't express a reused component getting a new param, which is how the bug hid
- **Dock state is read-only from outside.** `DockService` keeps private writable signals and exposes `asReadonly()` views. `app.ts` and `menu-bar.service.ts` each had their own copy of "minimize this app" writing the Map directly; both now call `minimizeApp()`
- **Angular guide, lesson 04: signals** (`/thoughts/angular-04-signals`). Demos show three synchronous writes producing one effect run, and a `linkedSignal` shipping choice that resets when the country changes but stays writable
- The lesson kicker says "Part 04" instead of "04 of 13", so the page doesn't show two different totals now that the series nav counts what's actually published
- Initial bundle 377.25 kB → 384.14 kB. I measured it rather than guessed: a build without `RouterLink` is 377.83 kB, so the router's link directive is the 6.3 kB. I'm keeping it, because real prerendered links and correct modifier-click handling are worth it and later lessons reuse it, but there's now 16 kB of headroom under the 400 kB budget

## 2026-11-21 - version 1.4.2

- **fix: ⌃⌥Space never opened Spotlight.** `App.onKeydown` called `shortcuts.handleKeydown(event)` twice per keydown, so every toggle shortcut flipped and flipped straight back, and ⌃⌥Tab cycled two windows at a time. It's now bound once through `host: { '(document:keydown)': … }` instead of `@HostListener`
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.2",
"version": "1.4.3",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
7 changes: 1 addition & 6 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,7 @@ export class App {

onWindowMinimized(windowId: string, appId: string): void {
this.windowManager.minimizeWindow(windowId);
const running = this.dockService.runningApps();
if (running.has(appId)) {
const map = new Map(running);
map.set(appId, 'minimized');
this.dockService.runningApps.set(map);
}
this.dockService.minimizeApp(appId);
}

onWindowMaximized(windowId: string): void {
Expand Down
7 changes: 1 addition & 6 deletions src/app/menu-bar/menu-bar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,7 @@ export class MenuBarService {
const win = this.activeWindow();
if (!win) return;
this.windowManager.minimizeWindow(win.id);
const running = this.dock.runningApps();
if (running.has(win.appId)) {
const map = new Map(running);
map.set(win.appId, 'minimized');
this.dock.runningApps.set(map);
}
this.dock.minimizeApp(win.appId);
}

private zoomActiveWindow(): void {
Expand Down
16 changes: 16 additions & 0 deletions src/app/shared/dock.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ describe('DockService', () => {
service = TestBed.inject(DockService);
});

it('exposes its state read-only, so only the service can change it', () => {
expect('set' in service.runningApps).toBe(false);
expect('set' in service.pinnedApps).toBe(false);
expect('set' in service.transientApps).toBe(false);
});

it('minimizeApp marks a running app minimized', () => {
service.minimizeApp('finder');
expect(service.getState('finder')).toBe('minimized');
});

it('minimizeApp ignores an app that is not running', () => {
service.minimizeApp('terminal');
expect(service.isRunning('terminal')).toBe(false);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
Expand Down
39 changes: 30 additions & 9 deletions src/app/shared/dock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export interface DockItem {

export type AppState = 'running' | 'focused' | 'minimized';

/**
* [ng-04 signals] A signal store: private writable signals, public read-only
* views, and methods that are the only way to change state.
*
* runningApps used to be a public WritableSignal, and both app.ts and
* menu-bar.service.ts had grown their own copy of "minimize this app" that
* wrote the Map directly. asReadonly() makes that a compile error, and
* minimizeApp() is now the one place the rule lives.
*/
@Injectable({ providedIn: 'root' })
export class DockService {
readonly pinnedApps = signal<DockItem[]>([
Expand All @@ -20,13 +29,15 @@ export class DockService {
{ id: 'thoughts', label: 'Thoughts', icon: '💭', color: '#FF9800', pinned: true },
{ id: 'settings', label: 'Settings', icon: '⚙️', color: '#607D8B', pinned: true },
{ id: 'contact', label: 'Contact', icon: '✉️', color: '#03A9F4', pinned: true },
]);
]).asReadonly();

private readonly runningAppsState = signal<Map<string, AppState>>(new Map([['finder', 'focused']]));
/** Map of app id → current state */
readonly runningApps = signal<Map<string, AppState>>(new Map([['finder', 'focused']]));
readonly runningApps = this.runningAppsState.asReadonly();

private readonly transientAppsState = signal<DockItem[]>([]);
/** Apps running but not pinned — shown after the separator */
readonly transientApps = signal<DockItem[]>([]);
readonly transientApps = this.transientAppsState.asReadonly();

readonly focusedAppId = computed(() => {
for (const [id, state] of this.runningApps()) {
Expand Down Expand Up @@ -64,7 +75,7 @@ export class DockService {
} else if (currentState === 'focused') {
// Already focused — minimize all windows of this app
running.set(app.id, 'minimized');
this.runningApps.set(running);
this.runningAppsState.set(running);
} else {
// Running but not focused (minimized or background) — focus it
this.focusApp(app.id, running);
Expand All @@ -82,11 +93,11 @@ export class DockService {
}

map.set(app.id, 'focused');
this.runningApps.set(map);
this.runningAppsState.set(map);

// If app is not pinned and not already transient, add it
if (!app.pinned && !this.transientApps().some((a) => a.id === app.id)) {
this.transientApps.update((apps) => [...apps, app]);
this.transientAppsState.update((apps) => [...apps, app]);
}
}

Expand All @@ -100,15 +111,25 @@ export class DockService {
}

map.set(appId, 'focused');
this.runningApps.set(map);
this.runningAppsState.set(map);
}

/** Mark a running app minimized. An app that isn't running stays not running. */
minimizeApp(appId: string): void {
if (!this.runningApps().has(appId)) return;
// A new Map, not running.set() on the current one: a signal compares by
// reference, so mutating in place would notify nobody.
const running = new Map(this.runningApps());
running.set(appId, 'minimized');
this.runningAppsState.set(running);
}

closeApp(appId: string): void {
const running = new Map(this.runningApps());
running.delete(appId);
this.runningApps.set(running);
this.runningAppsState.set(running);

// Remove from transient if present
this.transientApps.update((apps) => apps.filter((a) => a.id !== appId));
this.transientAppsState.update((apps) => apps.filter((a) => a.id !== appId));
}
}
68 changes: 68 additions & 0 deletions src/app/thoughts-content/lessons/lesson-04-signals.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 { Lesson04Signals } from './lesson-04-signals';

expect.extend(axeMatchers);

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

const text = (selector: string) => el.querySelector(selector)?.textContent ?? '';
const effectRuns = () => el.querySelectorAll('.effect-log li').length;

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

it('is registered as the lesson page for its thought', () => {
expect(LESSON_PAGES['angular-04-signals']).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('computed total follows its inputs', async () => {
expect(text('#signal-total')).toContain('$12');
el.querySelector<HTMLButtonElement>('#bump-one')!.click();
await fixture.whenStable();
expect(text('#signal-total')).toContain('$24');
});

it('three synchronous writes run the effect once, with the final value', async () => {
const before = effectRuns();
el.querySelector<HTMLButtonElement>('#bump-three')!.click();
await fixture.whenStable();

expect(effectRuns()).toBe(before + 1);
expect(text('.effect-log li:last-child')).toContain('$48');
});

it('linkedSignal resets the shipping choice when the country changes, but stays writable', async () => {
const choose = async (selector: string, value: string) => {
const select = el.querySelector<HTMLSelectElement>(selector)!;
select.value = value;
select.dispatchEvent(new Event('change'));
await fixture.whenStable();
};

await choose('#shipping', 'Express');
expect(text('#shipping-choice')).toContain('Express');

await choose('#country', 'US');
expect(text('#shipping-choice')).toContain('Ground');
});

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