Skip to content

Export model: lift three per-document facts out of cljs_project and vanilla_js#51

Merged
avanelsas merged 3 commits into
mainfrom
feature/export-model-action-of-group
May 12, 2026
Merged

Export model: lift three per-document facts out of cljs_project and vanilla_js#51
avanelsas merged 3 commits into
mainfrom
feature/export-model-action-of-group

Conversation

@avanelsas
Copy link
Copy Markdown
Owner

Summary

First batch of the audit's item 6 ("plugins are re-deriving facts the export model should own"). Three contained extractions; `bareforge.export.model` grows three small surfaces, plugins lose ~70 lines net plus three round-trips back through `m/get-node` to read fields already in scope.

  • `action-target-of-group-ns` — `emit-action-event` and `step->thread-form` both walked a group's `:fields` to find an action step's target-field `:of-group`, then composed `..db`. Same six lines at two sites; now one helper.
  • `resolve-explicit-field-owners` — `view-context` and `inline-entry` both wrapped `explicit-field-owners` with a `name->ns` resolution that falls back to the raw user-facing name. Same pattern, two sites; now one helper. The dead local `explicit-field-owners` alias in `cljs_project` is removed.
  • `find-sub-groups` carries `:source-sub` and `:source-field` — both plugins did `(m/get-node doc (:id sg))` after `find-sub-groups` had just walked the same node, only to read those two keys. Surface them on the entry directly. cljs_project's `tpl-child-sub-aliases` loses its `inst` rebind; vanilla_js's `node->js-hiccup` loses its `(assoc sg :source-field … :source-sub …)` re-pack entirely.

No behaviour change. Pinned by seven new tests in `model_test` covering each helper's contract.

The audit's fourth lift — a unified `resolve-template-source` that consolidates the `:source-sub / :source-field / auto-host` three-way `cond` repeated in `view-context`, `template-iteration-expr`, and `core-group-body` — is intentionally deferred. It's the biggest of the four (touches both plugins in three places each, returns a tagged map plugins switch on) and warrants its own focused PR.

Test plan

  • `clj-kondo --lint src test scripts` — 0 errors, 0 warnings
  • `cljfmt check` — clean
  • `npx shadow-cljs compile test` — 0 failures, 0 errors (seven new tests added)
  • `npx shadow-cljs release app` — 0 warnings
  • Spot-check: export the demo-store fixture under each plugin and compare against the golden output (byte-identical expected)

🤖 Generated with Claude Code

avanelsas and others added 3 commits May 12, 2026 14:34
emit-action-event and step->thread-form both walked the enclosing
group's :fields to find an action step's target-field :of-group, then
prepended <app-ns>.<og>.db — the same lookup at two sites of the same
plugin, and a fact about the document model that any future plugin
would re-derive.

Move it into bareforge.export.model as action-target-of-group-ns.
Both call sites now consume the helper. No behaviour change; pinned
by four new tests covering the collection-field hit, the scalar-field
miss, the unknown-target miss, and the app-ns prefix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
view-context and inline-entry both built {field → explicit-owner-ns}
by walking the subtree with explicit-field-owners and then mapping
each picked-owner name through name->ns (falling back to the raw
string when the name was absent). Identical six lines, two sites.

Move it into bareforge.export.model as resolve-explicit-field-owners,
fold the now-dead local alias for explicit-field-owners. Three new
tests pin the mapping, the unknown-name passthrough, and the
sub-group boundary.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… entries

Both cljs_project (view-context, template-iteration paths) and
vanilla_js/codegen (node->js-hiccup) read each sub-group instance's
:source-sub and :source-field by calling (m/get-node doc (:id sg))
after find-sub-groups had already walked the same node. The walk
already holds the child node — surface those two fields on every
returned entry so callers consume them directly.

Both plugins lose the m/get-node round-trip and the
{sg+src (assoc sg ...)} re-pack in vanilla_js disappears entirely.
No behaviour change; pinned by a new test that the demo-store's
cart-item template-instance children carry the source-* keys.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avanelsas avanelsas merged commit 7dfceeb into main May 12, 2026
1 check passed
@avanelsas avanelsas deleted the feature/export-model-action-of-group 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