Add some minimal docs

This commit is contained in:
Robin Nagpal 2018-07-31 10:12:25 -04:00
parent 71047c2dc5
commit 36636caa95
2 changed files with 23 additions and 3 deletions

View File

@ -86,7 +86,12 @@
;;; Rendering ;;; Rendering
(defn wrap-render [c] (defn wrap-render
"Calls the render function of the component. If the result of render function is
1) Vector (type one component) - Create a react element of the result and return
2) Function (type two component) - Recursively execute the function until we get a vector, and then create a react element of the result and return
3) else - XXX"
[c]
(let [f ($ c :reagentRender) (let [f ($ c :reagentRender)
_ (assert-callable f) _ (assert-callable f)
res (if (true? ($ c :cljsLegacyRender)) res (if (true? ($ c :cljsLegacyRender))

View File

@ -33,10 +33,18 @@
false)))))) false))))))
(defn- in-context [obj f] (defn- in-context [obj f]
"If 'f' uses '*ratom-context*' anywhere, it will be given 'obj'"
(binding [*ratom-context* obj] (binding [*ratom-context* obj]
(f))) (f)))
(defn- deref-capture [f r] (defn- deref-capture
"
1. Sets the '-captured' to nil
2. Gets the response by executing the function in context of component
3.
"
[f r]
(set! (.-captured r) nil) (set! (.-captured r) nil)
(when (dev?) (when (dev?)
(set! (.-ratomGeneration r) (set! generation (inc generation)))) (set! (.-ratomGeneration r) (set! generation (inc generation))))
@ -48,7 +56,14 @@
(._update-watching r c)) (._update-watching r c))
res)) res))
(defn- notify-deref-watcher! [derefed] (defn- notify-deref-watcher!
"When a component is rendered, the value of *ratom-context* is set as component,
Now when we deref anything inside the component, the derefed is added to
'component.captured' array.
Looks like component.captured keeps list of all the ratoms used inside it.
"
[derefed]
(when-some [r *ratom-context*] (when-some [r *ratom-context*]
(let [c (.-captured r)] (let [c (.-captured r)]
(if (nil? c) (if (nil? c)