diff --git a/README.md b/README.md index 38c7bd4..d29f0fb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@
-Snoopy is a profiling tool for React Native, that lets you snoop on the React Native Bridge. +Snoopy is a profiling tool for React Native, that lets you snoop on the React Native Bridge using the [MessageQueue spy feature](https://github.com/facebook/react-native/pull/9160). With Snoopy you can tame a stream of events, using [Rx](https://github.com/Reactive-Extensions/RxJS) and a few built-in goodies, @@ -21,7 +21,8 @@ and the Native world happen. Optimizing and catching unexpected (bad) communications can make or break your performance. Being that central and sensitive place, it made sense to have tooling built around it. -*NOTE*: Please see [bleeding edge](#bleeding-edge) to understand how Snoopy works and why you should only use it in DEV. +*NOTE*: Snoopy is a developer tool, and you might want to flag it under `__DEV__`. I felt +not doing this by default inside Snoopy will allow for creative uses even in production.

@@ -143,14 +144,17 @@ bars(info=>JSON.stringify(info.args).length)( ).subscribe() ``` -# Bleeding Edge +# React Native Below 0.33 -Snoopy works by taking the current `SPY_MODE` flag in the bridge queue, and building upon it. It makes the event reporting more -structured and generic, and plugs a firehose for you to sip events from. Since currently the existing `SPY_MODE` code only -prints logs and the Bridge->Queue->log chain is a singleton chain initialized much before userland code, I had to monkeypatch the queue to make it report to something more generic. +I've submitted a modification to `MessageQueue` that allows for more flexible bridge spy, +which was made available starting React Native v0.33. This will work seamlessly with Snoopy. -Although I have tested Snoopy in both old and modern React Native versions, hopefully, I could submit a PR that only handles the reporting mechanism into React Native upstream and the monkeypatch in Snoopy will go away. +For versions below 0.33, you have the option of locking to a legacy version of Snoopy which +installs these modifications via monkeypatching `MessageQueue`: +``` +$ npm i rn-snoopy@1.0.6 +``` # Contributing diff --git a/examples/Snoopful/package.json b/examples/Snoopful/package.json index 6b146a1..0f17ed8 100644 --- a/examples/Snoopful/package.json +++ b/examples/Snoopful/package.json @@ -8,7 +8,7 @@ "dependencies": { "ramda": "^0.22.1", "react": "15.2.1", - "react-native": "0.31.0", + "react-native": "0.34.0", "rxjs": "^5.0.0-beta.11" } } diff --git a/index.js b/index.js index 69653ab..0bc59f8 100644 --- a/index.js +++ b/index.js @@ -18,47 +18,13 @@ export default class Snoopy{ } static snoop(tracer){ - const nativeCall = this.nativeCall || MessageQueue.prototype.__nativeCall const spy = tracer.spy - const native = this.TO_NATIVE - const js = this.TO_JS - MessageQueue.prototype.__nativeCall = function(module, method, params, onFail, onSucc){ - nativeCall.apply(this, arguments) - const info = { type: native, module: this._remoteModuleTable[module], method: this._remoteMethodTable[module][method], args: params } - spy(info) - } - this.nativeCall = nativeCall - - const callFunction = this.callFunction || MessageQueue.prototype.__callFunction - MessageQueue.prototype.__callFunction = function(module, method, params, onFail, onSucc){ - const info = { type: js, module, method, args:params} - spy(info) - callFunction.apply(this, arguments) - } - this.callFunction = callFunction - - const invokeCallback = this.invokeCallback || MessageQueue.prototype.__invokeCallback - MessageQueue.prototype.__invokeCallback = function(cbID, args){ - const callback = this._callbacks[cbID]; - if(callback){ - const debug = this._debugInfo[cbID >> 1]; - const module = debug && this._remoteModuleTable[debug[0]]; - const method = debug && this._remoteMethodTable[debug[0]][debug[1]]; - const profileName = debug ? '' : cbID; - const info = { type: js, module:null, method:profileName, args } - spy(info) - } - invokeCallback.apply(this, arguments) - } - this.invokeCallback = invokeCallback - - this.snooping = true - + MessageQueue.spy(spy) return tracer } static clear(){ - this.snoop(()=>{}) + MessageQueue.spy() } } diff --git a/package.json b/package.json index 6d2cebf..b3b67b8 100644 --- a/package.json +++ b/package.json @@ -20,5 +20,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "1.0.6" + "version": "1.33.0" }