Files
ng-signals-template/src/app/shared/ui/molecules/async.component.ts
T
ehoandClaude Sonnet 5 c895929f58 fix: enable strict mode, honest HTTP boundary, and add routing
Three fixes to the parts of the template that contradicted its own
"illegal states unrepresentable" claim:

- tsconfig: turn on strict + strictTemplates (measured zero fallout —
  the codebase already typechecked cleanly, it just wasn't enforced).
- RemoteData<T> drops its unused error type parameter (Resource.error
  is always Error) and Failure now carries a real Error. Pages read the
  union with @let instead of re-deriving from the resource, which
  deletes the non-null assertion strictNullChecks would otherwise flag.
- users.adapter.ts never checked response.ok, so an HTTP error resolved
  as a garbage Success and crashed instead of reaching RemoteData's
  Failure branch. New shared/infrastructure/http.ts adds the status
  check plus hand-written parse guards and abortSignal forwarding; the
  six fetch stubs across the test suite (which encoded the missing
  check) and adapter spec now cover the Failure and Empty paths.

Also adds real routing (@angular/router was a dependency with zero
imports and a fake "Back" button): /users and /users/:id are now
deep-linkable via withComponentInputBinding(), tested with
RouterTestingHarness driving real navigation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-01 10:29:47 +02:00

33 lines
873 B
TypeScript

import { Component, input, output } from '@angular/core';
import { SpinnerComponent } from '@shared/ui/atoms/spinner.component';
import type { RemoteData } from '@shared/application/remote-data';
@Component({
selector: 'app-async',
imports: [SpinnerComponent],
template: `
@switch (data().tag) {
@case ('Loading') {
<app-spinner />
}
@case ('Empty') {
<p>{{ emptyText() }}</p>
}
@case ('Failure') {
<p role="alert">{{ errorText() }}</p>
<button type="button" (click)="retry.emit()">{{ retryText() }}</button>
}
@case ('Success') {
<ng-content />
}
}
`,
})
export class AsyncComponent<T> {
data = input.required<RemoteData<T>>();
emptyText = input('No data.');
errorText = input('Something went wrong.');
retryText = input('Retry');
retry = output<void>();
}