Skip to content

Instantly share code, notes, and snippets.

@puppybits
Forked from Peeja/rerender.cljs
Created September 7, 2018 17:20
Show Gist options
  • Save puppybits/55b6fa434c250b21756df35b8e25d4d1 to your computer and use it in GitHub Desktop.
Save puppybits/55b6fa434c250b21756df35b8e25d4d1 to your computer and use it in GitHub Desktop.
What it appears to take to re-render the React tree when Figwheel reloads.
;; Re-render when Figwheel reloads.
(gevents/listen js/document.body
"figwheel.js-reload"
(fn []
(let [root-component (om-next/app-root (compassus/get-reconciler a))]
(letfn [(js-vals [o]
(map #(aget o %) (js-keys o)))
;; Finds the children of a React internal instance of a component.
;; That could be a single _renderedComponent or several
;; _renderedChildren.
(children [ic]
(or (some-> (.-_renderedComponent ic) vector)
(js-vals (.-_renderedChildren ic))))
(descendant-components [c]
;; Walk the tree finding tall of the descendent internal instances...
(->> (tree-seq #(seq (children %)) children (.-_reactInternalInstance c))
;; ...map to the public component instances...
(map #(.-_instance %))
;; ...and remove the nils, which are from DOM nodes.
(remove nil?)))]
(doseq [c (descendant-components root-component)]
(.forceUpdate c))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment