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.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
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
the conceptual leap here is: instead of thinking of DOM fragments as values, think of them as constructors, and programs are values
Very helpful, thank you!
Is there a rebinding teleport example somewhere?
there's a markdown example that uses portals in the tutorial doc
C-f "Portals"