Last active
April 6, 2017 01:07
-
-
Save mridgway/26b84cfe73504fdddeb31e3dbad04703 to your computer and use it in GitHub Desktop.
Poor mans React dev tools
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
var hook = { | |
inject: (renderer) => { | |
var oldMountComponent = renderer.Reconciler.mountComponent, | |
oldPerformUpdateIfNecessary = renderer.Reconciler.performUpdateIfNecessary, | |
oldReceiveComponent = renderer.Reconciler.receiveComponent, | |
oldUnmountcomponent = renderer.Reconciler.unmountComponent; | |
renderer.Reconciler.mountComponent = function overrideMountComponent() { | |
hook.emit('mountComponent', Array.prototype.slice.call(arguments)); | |
return oldMountComponent.apply(renderer.Reconciler, arguments); | |
} | |
renderer.Reconciler.performUpdateIfNecessaryComponent = function overridePerformUpdateIfNecessaryComponent() { | |
hook.emit('performUpdateIfNecessaryComponent', Array.prototype.slice.call(arguments)); | |
return oldPerformUpdateIfNecessary.apply(renderer.Reconciler, arguments); | |
} | |
renderer.Reconciler.receiveComponent = function overridReceiveComponent() { | |
hook.emit('receiveComponent', Array.prototype.slice.call(arguments)); | |
return oldReceiveComponent.apply(renderer.Reconciler, arguments); | |
} | |
renderer.Reconciler.unmountComponent = function overridUnmountComponent() { | |
hook.emit('unmountComponent', Array.prototype.slice.call(arguments)); | |
return oldUnmountcomponent.apply(renderer.Reconciler, arguments); | |
} | |
}, | |
emit: (eventName, value) => { | |
console.log(eventName, value); | |
} | |
}; | |
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment