-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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