Created
September 9, 2016 23:00
-
-
Save Peeja/eccd5e8169709c12ec0420c86beb49b9 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 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
Thanks. I've been looking for this script all day. It only needed a slight change to work in React Native.