Skip to content

refactor: Extract Ali je vroče read model#418

Open
jalezi wants to merge 3 commits into
chore/prepare-repo-for-agentsfrom
refactor/ali-je-vroce-read-model
Open

refactor: Extract Ali je vroče read model#418
jalezi wants to merge 3 commits into
chore/prepare-repo-for-agentsfrom
refactor/ali-je-vroce-read-model

Conversation

@jalezi

@jalezi jalezi commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Stacking note

This PR is stacked on #416 and should be reviewed against chore/prepare-repo-for-agents, not directly against main.

That matters because the new frontend-check workflow runs yarn typecheck, which depends on the TypeScript configuration fix from #416. The unrelated chore/upgrade-yarn-deps branch is no longer part of this branch chain.

Why

The Ali je vroče flow had several read-model responsibilities spread across the Solid hook, query helpers, network helpers, and an optimistic-update utility. Understanding station selection required following localStorage preference migration, station shape conversion, current-hotness display mapping, raw Datasette/Vremenar transformations, cache lookup behavior, and optimistic placeholders across multiple modules.

This PR deepens that module boundary by putting the station/current-hotness read model behind a plain TypeScript interface while preserving the existing UI-facing useWeatherData() return shape.

What changed

  • Added code/ali-je-vroce/model/readModel.ts as a plain read-model module.
  • Moved selected-station preference reading/writing, legacy migration, validation, and storage-error fallback into the read model.
  • Moved station preference conversion and current-hotness display-field mapping into the read model.
  • Moved raw Datasette station-row and Vremenar/percentile response transformations into the read model.
  • Replaced the old optimistic-update utility with read-model-owned optimistic display policy and removed the orphaned file.
  • Added Node test coverage for preference migration, storage failure fallback, malformed preferences, station conversion, display mapping, optimistic display, and raw response transformation.
  • Added yarn test and wired yarn test plus yarn typecheck into the website build workflow.

Impact

The page behavior is intended to stay the same, with a few deliberate improvements:

  • Station-switch optimistic cache lookup now uses the same string station id shape as the query cache.
  • Malformed stored station preferences reset to the default station instead of leaking invalid shapes into UI state.
  • Invalid/non-finite percentile values now fail fast instead of risking an incorrect current-hotness bucket.
  • Preference storage errors still degrade gracefully, so blocked/unavailable localStorage does not break page initialization or station switching.

Follow-up

Created #417 for the next related slice: reducing duplicated query/cache fallback policy across hooks/queries.ts, utils/prefetching.ts, and hooks/useWeatherData.ts.

Validation

  • yarn test
  • yarn typecheck
  • yarn build

@jalezi jalezi added javascript Pull requests that update Javascript code typescript Typescript migration github_actions Pull requests that update GitHub Actions code labels Jun 21, 2026
@jalezi jalezi requested a review from Copilot June 21, 2026 06:58
@jalezi jalezi changed the base branch from main to chore/prepare-repo-for-agents June 21, 2026 07:01
@jalezi jalezi marked this pull request as ready for review June 21, 2026 07:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extracts the “Ali je vroče” station/current-hotness read model into a plain TypeScript module (with tests) while keeping the existing useWeatherData() UI-facing shape, and wires yarn test + yarn typecheck into CI.

Changes:

  • Introduces code/ali-je-vroce/model/readModel.ts to own preference storage/migration, station shape conversion, current-hotness display mapping, optimistic display policy, and raw response transforms.
  • Updates useWeatherData + helpers.ts to use the read model and removes the old optimistic-update utility.
  • Adds Node test coverage for the read model and runs yarn test + yarn typecheck in the build workflow.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.json Adjusts TS path-mapping configuration comment / baseUrl usage.
skills-lock.json Adds skills lock scaffold for agent-skill management.
README.md Documents canonical vs generated agent skills locations and sync command.
package.json Adds sync-skills, updates postinstall, adds test and typecheck scripts.
code/ali-je-vroce/utils/optimistic.ts Removes legacy optimistic-update helper (now owned by read model).
code/ali-je-vroce/model/readModel.ts New read-model module (prefs, transformations, optimistic display).
code/ali-je-vroce/model/readModel.test.ts New Node tests for the read-model behavior.
code/ali-je-vroce/hooks/useWeatherData.ts Switches UI hook to read-model state/transformations + new optimistic policy.
code/ali-je-vroce/helpers.ts Delegates station/current-hotness transforms to the read model.
CLAUDE.md Points Claude Code at the canonical agent instructions.
AGENTS.md Adds canonical, tool-neutral agent instruction entrypoint and skills guidance.
.gitignore Ignores generated .claude/skills copy.
.github/workflows/copilot-setup-steps.yml Adds Copilot coding-agent setup workflow for consistent environment.
.github/workflows/build.yaml Runs yarn test and yarn typecheck in CI before yarn build.
.github/instructions/typescript-solid-eleventy.instructions.md Adds scoped frontend/TS/Solid/Eleventy guidance.
.github/instructions/testing.instructions.md Adds scoped testing/validation guidance.
.github/instructions/security.instructions.md Adds scoped security guidance for code/workflows/content/data.
.github/instructions/performance.instructions.md Adds scoped performance guidance for site + frontend.
.github/instructions/documentation.instructions.md Adds scoped docs/content guidance.
.github/instructions/code-review.instructions.md Adds scoped code review guidance for this repo.
.github/copilot-instructions.md Adds canonical repository-wide Copilot instructions.
.github/agents/software-engineer.agent.md Adds “Software Engineer” agent definition.
.github/agents/reviewer.agent.md Adds “Reviewer” agent definition.
.github/agents/debugger.agent.md Adds “Debugger” agent definition.
.github/agents/architect.agent.md Adds “Architect” agent definition.
.agents/skills/write-tests/SKILL.md Adds reusable “write-tests” skill.
.agents/skills/setup-component/SKILL.md Adds reusable “setup-component” skill.
.agents/skills/refactor-code/SKILL.md Adds reusable “refactor-code” skill.
.agents/skills/generate-docs/SKILL.md Adds reusable “generate-docs” skill.
.agents/skills/debug-issue/SKILL.md Adds reusable “debug-issue” skill.
.agents/skills/code-review/SKILL.md Adds reusable “code-review” skill.

Comment thread code/ali-je-vroce/model/readModel.ts
Comment on lines +61 to +63
const initialState = createInitialReadModelState(localStorage);
const [stationId, setStationId] = createSignal(String(initialState.selectedStation?.value));
const [state, setState] = createStore<ReadModelState>(initialState);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. The read model catches getItem/setItem/removeItem failures, but this comment catches the missing outer edge: evaluating localStorage itself can throw before the read-model fallback runs. Implemented getBrowserPreferenceStorage() in the Solid hook, which falls back to a no-op preference storage adapter when browser storage is unavailable. Covered by existing storage-failure read-model tests plus yarn test / yarn typecheck after the change. Commit: 49103f9.


// Save selected station to local storage (in cached format)
setPreference('selectedStation', cachedFormat);
writeSelectedStationPreference(localStorage, selectedStation);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. Same underlying issue as the initialization path: passing localStorage directly means the getter can throw before writeSelectedStationPreference has a chance to handle storage errors. The hook now acquires preferenceStorage once through the safe wrapper and uses that same adapter for writes during station changes. Commit: 49103f9.

@jalezi jalezi requested review from ntadej and stefanb June 21, 2026 07:10
@jalezi jalezi changed the title [codex] Extract Ali je vroče read model refactor: Extract Ali je vroče read model Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github_actions Pull requests that update GitHub Actions code javascript Pull requests that update Javascript code typescript Typescript migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants