Skip to content

Instantly share code, notes, and snippets.

@Peeja
Created September 9, 2016 23:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Peeja/eccd5e8169709c12ec0420c86beb49b9 to your computer and use it in GitHub Desktop.
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.
;; 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))))))
@puppybits
Copy link

Thanks. I've been looking for this script all day. It only needed a slight change to work in React Native.

@decoursin
Copy link

Thank you, this is great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment