Skip to content

Export model: unify template-source resolution behind resolve-template-source#52

Merged
avanelsas merged 1 commit into
mainfrom
feature/export-resolve-template-source
May 12, 2026
Merged

Export model: unify template-source resolution behind resolve-template-source#52
avanelsas merged 1 commit into
mainfrom
feature/export-resolve-template-source

Conversation

@avanelsas
Copy link
Copy Markdown
Owner

Summary

Follow-up to #51 and the final piece of the audit's item 6. Three places — `cljs_project`'s `view-context` (template-instance require aliases) + `core-group-body` (root-level template iteration), and `vanilla_js/codegen`'s `template-iteration-expr` — each ran the same three-way `cond` to decide where a template instance's records come from:

  1. Explicit `:source-sub` on the instance.
  2. Explicit `:source-field`, resolved to the owning group via the field-owner index.
  3. Neither set — fall back to the unique stateful host whose `:of-group` collection points at the template.

Three plugins, three branches, one fact about the document. Lift it into `bareforge.export.model/resolve-template-source`, which returns a tagged map: `{:kind :source-sub :sub …}` / `{:kind :source-field :owner-ns … :field …}` / `{:kind :auto-host :owner-ns … :field-name …}`. Each call site now `case`s on `:kind` to format its target-specific sub-ref string.

Behaviour deltas

  • `view-context`'s `tpl-child-sub-aliases` and `template-iteration-expr`: pure refactor, identical output.
  • `core-group-body` (root-level template entry): previously had no `:auto-host` branch — its three-way `cond` covered `:source-sub`, `:source-field`, and an `:else "::!no-source-for-template"` placeholder. Now it routes `:auto-host` to the same `.subs/` shape the other two sites use. Demo-store doesn't currently trigger this at root, but any future root-level template-instance with no explicit source (and a single `:of-group` host) will resolve correctly instead of falling through to the placeholder.

Test plan

  • `clj-kondo --lint src test scripts` — 0 errors, 0 warnings
  • `cljfmt check` — clean
  • `npx shadow-cljs compile test` — 0 failures, 0 errors (5 new tests pin source-sub precedence, source-field owner resolution, missing-owner nil, demo-store auto-host fallback, and the nil-when-nothing-resolves case)
  • `npx shadow-cljs release app` — 0 warnings
  • Manual smoke: export demo-store under both plugins; diff codegen output against pre-merge — no diff expected

Item 6 status

With this merged, audit item 6 ("plugins re-derive facts the model should own") is done — both plugins now consume `action-target-of-group-ns`, `resolve-explicit-field-owners`, `find-sub-groups`'s carried source-* fields, and `resolve-template-source` instead of redoing the math per plugin.

🤖 Generated with Claude Code

…e-source

cljs_project (view-context tpl-child-sub-aliases + core-group-body)
and vanilla_js/codegen (template-iteration-expr) each ran the same
three-way cond — source-sub > source-field-owner > stateful-host
auto-fallback — to decide where a template instance's records come
from. Three plugins, three branches, one fact about the document.

Move the resolution into bareforge.export.model/resolve-template-source.
It returns a tagged map (`{:kind :source-sub | :source-field |
:auto-host …}`) and each call site switches on `:kind` to format the
target-specific sub-ref string. The three sites lose ~50 lines of
duplicated logic; both plugins gain a hardened `:auto-host` branch
in core-group-body (was `:else "::!no-source-for-template"` before,
now matches the demo-store auto-host pattern correctly).

Five new tests pin the precedence (source-sub wins over field /
auto-host), the owner-resolution path, the no-owner / no-host nil
cases, and the demo-store cart-item auto-host fallback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avanelsas avanelsas merged commit 84849d6 into main May 12, 2026
1 check passed
@avanelsas avanelsas deleted the feature/export-resolve-template-source branch May 12, 2026 13:52
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