Liking cljdoc? Tell your friends :D

dev.zeko.stube.keyed

Keyed-children primitive.

A parent can declare an ordered set of child component instances identified by stable user-facing keys instead of fixed slot names. When the set changes, the kernel emits per-child element fragments (:append / :remove / :outer against the container) rather than re-rendering the whole parent.

Surface

  • Effect (s/set-keyed-children slot pairs) where pairs is [[stable-key embed-spec] ...] in display order. Triggers the diff fold in reconcile!.
  • Render helper (s/keyed-children self slot) returns hiccup for the container <div id=PARENTIID--SLOTNAME> with each child's current HTML inlined in order.

State shape on the parent instance:

:instance/keyed-slots
{:slot/cols {:order    [:c1 :c2]
             :children {:c1 {:iid "ix-000005"
                             :embed {:embed/type :demo/counter
                                     :embed/args {:start 0}}}
                        :c2 {:iid "ix-000006"
                             :embed {…}}}}}

Diff rules

  • Key in new but not old → mint, :start, emit :append at the right position (:append/:prepend/:after).
  • Key in old but not new → :stop, remove, emit :remove targeting the child iid.
  • Same key, different embed args → re-:init the child in place (iid preserved, descendants rebuilt), emit :outer at the child iid.
  • Same key, same embed args → no fragment.
  • Different order, same key-set → emit one :outer against the whole container (cheaper than a parent re-render; still distinguishable from individual diffs in replay traces).

Before the parent has been rendered the first time, reconcile! performs all the bookkeeping silently and emits no fragments — the parent's normal render-frame will pick up the populated state and emit one container.

Keyed-children primitive.

A parent can declare an ordered set of child component instances
identified by stable user-facing keys instead of fixed slot names.
When the set changes, the kernel emits per-child element fragments
(`:append` / `:remove` / `:outer` against the container) rather than
re-rendering the whole parent.

Surface
-------

- **Effect** `(s/set-keyed-children slot pairs)` where `pairs` is
  `[[stable-key embed-spec] ...]` in display order.  Triggers the
  diff fold in [[reconcile!]].
- **Render helper** `(s/keyed-children self slot)` returns hiccup
  for the container `<div id=PARENTIID--SLOTNAME>` with each child's
  current HTML inlined in order.

State shape on the parent instance:

    :instance/keyed-slots
    {:slot/cols {:order    [:c1 :c2]
                 :children {:c1 {:iid "ix-000005"
                                 :embed {:embed/type :demo/counter
                                         :embed/args {:start 0}}}
                            :c2 {:iid "ix-000006"
                                 :embed {…}}}}}

Diff rules
----------

- Key in new but not old           → mint, `:start`, emit `:append`
                                     at the right position
                                     (`:append`/`:prepend`/`:after`).
- Key in old but not new           → `:stop`, remove, emit `:remove`
                                     targeting the child iid.
- Same key, different embed args   → re-`:init` the child in place
                                     (iid preserved, descendants rebuilt),
                                     emit `:outer`
                                     at the child iid.
- Same key, same embed args        → no fragment.
- Different order, same key-set    → emit one `:outer` against the
                                     whole container (cheaper than a
                                     parent re-render; still
                                     distinguishable from individual
                                     diffs in replay traces).

Before the parent has been rendered the first time, `reconcile!`
performs all the bookkeeping silently and emits no fragments — the
parent's normal `render-frame` will pick up the populated state and
emit one container.
raw docstring

child-iidclj

(child-iid self slot key)

Look up the iid of the child mounted under slot/key on self.

Look up the iid of the child mounted under `slot`/`key` on `self`.
sourceraw docstring

container-idclj

(container-id parent-id slot)

DOM id of the keyed-children container element under parent-id/slot.

DOM id of the keyed-children container element under `parent-id`/`slot`.
sourceraw docstring

reconcile!clj

(reconcile! conv parent-id slot pairs run-effects-fn)

Apply the :set-keyed-children effect: update parent-id's :instance/keyed-slots for slot to match pairs, mint/remove/ re-init children, and emit per-change element fragments when the parent is already rendered. Returns [conv' fragments].

Apply the `:set-keyed-children` effect: update `parent-id`'s
`:instance/keyed-slots` for `slot` to match `pairs`, mint/remove/
re-init children, and emit per-change element fragments when the
parent is already rendered.  Returns `[conv' fragments]`.
sourceraw docstring

render-children-hiccupclj

(render-children-hiccup self slot)

Inline the child instances currently registered for slot on self. Mirrors render/render-slot: looks each child up in render/*conv*, invokes its :render, returns the hiccup so Chassis serialises it in one pass with the parent.

Inline the child instances currently registered for `slot` on `self`.
Mirrors `render/render-slot`: looks each child up in `render/*conv*`,
invokes its `:render`, returns the hiccup so Chassis serialises it in
one pass with the parent.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close