Skip to content

Instantly share code, notes, and snippets.

@mridgway
Last active April 6, 2017 01:07
Show Gist options
  • Save mridgway/26b84cfe73504fdddeb31e3dbad04703 to your computer and use it in GitHub Desktop.
Save mridgway/26b84cfe73504fdddeb31e3dbad04703 to your computer and use it in GitHub Desktop.
Poor mans React dev tools
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