Skip to content

refactor(resources): extract AssetDecoder from Loader (Loader split, Slice 2/4)#415

Merged
Exoridus merged 4 commits into
mainfrom
worktree-loader-split-slice1
Jul 26, 2026
Merged

refactor(resources): extract AssetDecoder from Loader (Loader split, Slice 2/4)#415
Exoridus merged 4 commits into
mainfrom
worktree-loader-split-slice1

Conversation

@Exoridus

Copy link
Copy Markdown
Owner

Summary

  • Extracts the fetch/handler-dispatch/cache-strategy plumbing from Loader into a standalone AssetDecoder class (src/resources/AssetDecoder.ts), continuing the internal Loader-split effort started in Slice 1 (refactor(resources): extract AssetTypeRegistry from Loader (Loader split, Slice 1/4) #414, AssetTypeRegistry).
  • AssetDecoder deliberately never touches the resident-resource map: every resolved value is handed to a constructor-injected storeResource callback (currently wired to Loader._storeResource), so Slice 3 (AssetResidency) can repoint that one callback without redesigning this class.
  • Pure internal refactor — no public API change. Loader's public methods keep their exact signatures/JSDoc; basePath/fetchOptions become thin delegates. docs:api:check confirms zero drift in the generated API docs.
  • destroy() teardown order (factories → stores → handlers) is preserved, including the regression coverage added after the Slice 1 review found a real ordering bug.

Test plan

  • pnpm typecheck — clean
  • pnpm test:core — 329/329 files, 5326 passed, 15 skipped, 0 failed
  • pnpm verify:quick (typecheck + guides/examples/type-tests/packages typecheck + lint + format + docs:api:check) — clean, only pre-existing unrelated warnings
  • New test/resources/asset-decoder.test.ts (12 tests) exercises AssetDecoder standalone against a real AssetTypeRegistry and faked I/O boundary (CacheStrategy/CacheStore)
  • Task-level and final whole-branch review both completed via subagent-driven-development (one fix round each: a loosened test assertion in Task 1, and lint/format/doc findings in the final review) — all findings verified addressed

Exoridus added 4 commits July 26, 2026 05:23
Standalone class owning Loader's URL resolution, cache-strategy
dispatch, bindAsset handler invocation, and container byte-injection.
Resolved resources are handed to a constructor-injected storeResource
callback rather than stored directly, so this class stays "identity +
bytes/handler in, resource out" per the Loader-split design doc. Not
yet wired into Loader — this commit is additive only, proven correct
in isolation against fakes. Loader.ts's own copy of this logic still
exists unchanged.
…hFetch test

AssetTypeRegistry.bindAsset's toRequest closure nests non-source fields
under 'options'. Update test to expect { source: 'hero.png', options: { scale: 2 } }
instead of loosened assertions. Verifies exact option-merging behavior as specified.

Fixes: code-review feedback on test assertion rigor.
Verified: all tests pass, typecheck clean.
…ce 2b)

Loader composes one AssetDecoder instance and delegates URL
resolution, cache-strategy dispatch, bindAsset handler invocation, and
container byte-injection to it. Resource storage stays on
Loader._storeResource, reached from AssetDecoder through a
constructor-injected callback — AssetDecoder itself never touches the
resident-resource map, per the Loader-split design doc. No public API
change — basePath/fetchOptions keep their exact getter/setter
semantics as thin delegates.

Loader.ts drops the fetch/dispatch plumbing; the extracted logic is
unchanged, only relocated and proven independently in AssetDecoder's
own test file (prior commit).
…r split

Fix simple-import-sort violations in AssetDecoder.ts and asset-decoder.test.ts,
apply Prettier's arrow-last-argument expansion to four register() call sites
in the test file, import AssetHandler so its JSDoc {@link} resolves, trim the
duplicated basePath doc comment to point back at Loader.basePath, and clarify
the destroy() teardown-order comment to name this._decoder.destroy() as the
store-destroy step.
@Exoridus
Exoridus enabled auto-merge (squash) July 26, 2026 03:55
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 7.83kB (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
exo-esm-esm 873.31kB 620 bytes (0.07%) ⬆️
exo-esm-modules-esm 3.93MB 5.08kB (0.13%) ⬆️
exo-iife-min-Exo-iife 881.05kB 620 bytes (0.07%) ⬆️
exo-full-iife-Exo-iife 2.8MB 1.51kB (0.05%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: exo-iife-min-Exo-iife

Assets Changed:

Asset Name Size Change Total Size Change (%)
exo.iife.min.js 620 bytes 881.05kB 0.07%

Files in exo.iife.min.js:

  • ./src/resources/Loader.ts → Total Size: 76.94kB

  • ./src/resources/AssetDecoder.ts → Total Size: 7.53kB

view changes for bundle: exo-esm-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
exo.esm.js 620 bytes 873.31kB 0.07%

Files in exo.esm.js:

  • ./src/resources/AssetDecoder.ts → Total Size: 7.53kB

  • ./src/resources/Loader.ts → Total Size: 76.94kB

view changes for bundle: exo-esm-modules-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
resources/Loader.js -5.29kB 78.18kB -6.34%
resources/Loader.d.ts -2.01kB 35.05kB -5.43%
resources/AssetDecoder.js (New) 7.61kB 7.61kB 100.0% 🚀
resources/AssetDecoder.d.ts (New) 4.78kB 4.78kB 100.0% 🚀

Files in resources/Loader.js:

  • ./src/resources/Loader.ts → Total Size: 76.94kB

Files in resources/AssetDecoder.js:

  • ./src/resources/AssetDecoder.ts → Total Size: 7.53kB
view changes for bundle: exo-full-iife-Exo-iife

Assets Changed:

Asset Name Size Change Total Size Change (%)
exo.full.iife.js 1.51kB 2.8MB 0.05%

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.59155% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/resources/Loader.ts 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Exoridus
Exoridus merged commit 6e7cf04 into main Jul 26, 2026
18 checks passed
@Exoridus
Exoridus deleted the worktree-loader-split-slice1 branch July 26, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant