Skip to content

Commit

Permalink
hidden mount point prop
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed May 16, 2024
1 parent d34d2a8 commit ee1fffb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/hyperfiddle/dom31.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@

(def node)

(defn get-mount-point [node] (aget node "mount-point"))
#?(:cljs
(let [key (js/Symbol.for "hyperfiddle.mount-point")]
(defn mount-point
([node] (aget node key))
([node v] (aset node key v)))))

#?(:cljs
(defn attach! [parent-node tag e]
(assert (instance? js/Node parent-node))
(m/observe (fn [!]
(! nil)
(let [mount-point (get-mount-point node)] ; TODO could this be inlined?
(let [mount-point (mount-point node)] ; TODO could this be inlined?
(e/insert! mount-point tag e)
#(e/remove! mount-point tag e))))))

Expand Down Expand Up @@ -113,14 +117,15 @@
element))

(e/defn Element [tag Body]
(let [e (.createElement js/document (name tag))
mp (e/mount-point)
tag (e/tag)]
(e/input (attach! node tag e)) ; mount and unmount element in parent
(e/join (e/mount-items e mp)) ; mount children in this node via mount point
(aset e "mount-point" mp) ; expose mount point to children ; TODO namespace and hide prop using js/Symbol
(binding [node e] ; run continuation
(Body.))))
(e/client
(let [e (.createElement js/document (name tag))
mp (e/mount-point)
tag (e/tag)]
(e/input (attach! node tag e)) ; mount and unmount element in parent
(e/join (e/mount-items e mp)) ; mount children in this node via mount point
(mount-point e mp) ; expose mount point to children
(binding [node e] ; run continuation
(Body.)))))

(defmacro element [tag & body]
`($ Element tag (e/fn [] (e/amb ~@body))))
Expand Down

0 comments on commit ee1fffb

Please sign in to comment.