2016-02-10 21:14:05 +00:00
|
|
|
(ns re-natal.support
|
|
|
|
(:require [om.next :refer-macros [ui]]))
|
|
|
|
|
2016-02-11 20:42:59 +00:00
|
|
|
(defonce root-nodes (atom {}))
|
2016-02-10 21:14:05 +00:00
|
|
|
|
2016-02-11 20:42:59 +00:00
|
|
|
(defn root-node!
|
2016-02-10 21:14:05 +00:00
|
|
|
"A substitute for a real root node (1) for mounting om-next component.
|
|
|
|
You have to call function :on-render and :on-unmount in reconciler :root-render :root-unmount function."
|
|
|
|
[id]
|
|
|
|
(let [content (atom nil)
|
|
|
|
instance (atom nil)
|
|
|
|
class (ui Object
|
|
|
|
(componentWillMount [this] (reset! instance this))
|
|
|
|
(render [_] @content))]
|
|
|
|
(swap! root-nodes assoc id {:on-render (fn [el]
|
|
|
|
(reset! content el)
|
|
|
|
(when @instance
|
|
|
|
(.forceUpdate @instance)))
|
|
|
|
:on-unmount (fn [])
|
|
|
|
:class class})
|
|
|
|
class))
|
|
|
|
(defn root-render
|
|
|
|
"Use this as reconciler :root-render function."
|
|
|
|
[el id]
|
|
|
|
(let [node (get @root-nodes id)
|
|
|
|
on-render (:on-render node)]
|
|
|
|
(when on-render (on-render el))))
|
|
|
|
|
|
|
|
(defn root-unmount
|
|
|
|
"Use this as reconciler :root-unmount function."
|
|
|
|
[id]
|
|
|
|
(let [node (get @root-nodes id)
|
|
|
|
unmount-fn (:on-unmount node)]
|
|
|
|
(when unmount-fn (unmount-fn))))
|
|
|
|
|