by dustingetz · 10y ago · 0 comments
cljs.user=> (ns foo.core (:require [reagent.core :as reagent]))
nil
foo.core=> (def ^:dynamic *foo* 42)
#'foo.core/*foo*
foo.core=> (defn inner [] [:div *foo*])
#'foo.core/inner
; React component call - broken
foo.core=> (defn root1 [] (binding [*foo* (inc *foo*)] [inner]))
#'foo.core/root1
foo.core=> (reagent/render-to-string [root1])
"<div ...>42</div>"
; Direct function call - works
foo.core=> (defn root2 [] (binding [*foo* (inc *foo*)] (inner)))
#'foo.core/root2
foo.core=> (reagent/render-to-string [root2])
"<div ...>43</div>"
A quick example of dynamic scope: cljs.user=> (def ^:dynamic *foo* 42)
#'cljs.user/*foo*
cljs.user=> (defn negate [x] (- x))
#'cljs.user/negate
cljs.user=> (binding [*foo* (inc *foo*)] (negate *foo*))
-43If you were to use dynamic scope, how would the variables be restored if one of the descendants updated via setState? It doesn't seem to me like it would work.
Also, not sure what "context hacks" you mean or what "web worker call stack serialization" is.
The problem with React Context is that it bypasses the general solution offered at language layer for a react-specific solution, essentially breaking any code written without prior knowledge of React.
If you have a concrete suggestion for something we could change in React I'd be happy to chat about it. I'd love to support CLJS better.
That's not how function components work, and i can easily imagine how to get lifecycle methods back (including optimizations) on function components