hyperfiddle

2025-10-05T13:27:07.244819Z

in the token pattern example, when-some is used to both define and place the button:

(when-some [t (dom/button (dom/text "toggle!")
                  (let [e (dom/On "click" identity nil)
                        [t err] (e/Token e)]
                    t))]
    ;; handle the token...
    )
in regular clojure, i'd use let to define something and use it later. but here, when-some seems to both define the button and place it in the dom tree immediately. is it an electric thing that defining a dom element always means placing it? is there a use case where you'd want to separate definition from placement? i couldn't think of one, but wanted to check if i'm missing something.

Dustin Getz (Hyperfiddle) 2025-10-05T13:56:59.965859Z

is it an electric thing that defining a dom element always means placing itYes, electric-dom uses an electric special form to introspect an element's location in the program DAG's lexical order and uses that information to position it correspondingly in the DOM. > is there a use case where you'd want to separate definition from placement? Use e/fn to thunk a DOM fragment, pass it around and call it to mount somewhere else

🙏 1
Dustin Getz (Hyperfiddle) 2025-10-05T14:00:25.563879Z

you can also rebind dom/node to teleport/portal, such as rendering a deep modal with css requirements that the modal container be near the root of the document

Dustin Getz (Hyperfiddle) 2025-10-05T14:08:11.594359Z

the conceptual leap here is: instead of thinking of DOM fragments as values, think of them as constructors, and programs are values

⚡ 2
2025-10-05T21:29:29.934479Z

Very helpful, thank you!

2025-10-05T21:30:34.452619Z

Is there a rebinding teleport example somewhere?

Dustin Getz (Hyperfiddle) 2025-10-05T23:43:10.768339Z

there's a markdown example that uses portals in the tutorial doc

Dustin Getz (Hyperfiddle) 2025-10-05T23:44:02.075079Z

C-f "Portals"

👍 1