Created
June 29, 2016 15:51
-
-
Save piranha/79e2b4ffd91178c871911fbda716a387 to your computer and use it in GitHub Desktop.
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
(ns mk.fe.core.why-update | |
(:require [cljsjs.react])) | |
(defn comp-did-update [prev-props prev-state] | |
(this-as this | |
(let [name (or (aget this "displayName") | |
(aget this "constructor" "displayName") | |
(aget this "constructor" "name")) | |
prev-state (aget prev-state ":rum/state") | |
state (aget (.-state this) ":rum/state")] | |
(when (= prev-state state) | |
(println name "update was avoidable!"))))) | |
(def orig-create-class js/React.createClass) | |
(def orig-did-update js/React.Component.prototype.componentDidUpdate) | |
(def Mixin #js {:componentDidUpdate comp-did-update}) | |
(defn enable! [] | |
(set! js/React.createClass | |
(fn [obj] | |
(when (nil? (aget obj "mixins")) | |
(aset obj "mixins" #js [])) | |
(aset obj "mixins" (.concat #js [Mixin] (aget obj "mixins"))) | |
(.call orig-create-class js/React obj))) | |
:wow) | |
(defn disable! [] | |
(set! js/React.createClass orig-create-class)) | |
(defonce much (enable!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment