Skip to content

Commit

Permalink
Merge 5aaeb1b into ce19cd6
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcsally committed Apr 11, 2020
2 parents ce19cd6 + 5aaeb1b commit 1a5e676
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
26 changes: 17 additions & 9 deletions extension/backend/fiber-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

/* eslint brace-style: off, camelcase: off, max-len: off, no-prototype-builtins: off, no-restricted-syntax: off, consistent-return: off, no-inner-declarations: off */
/* eslint no-use-before-define: off, no-var: off */
import circular from 'circular';

import { parseFunction } from './common';

var __ReactSightDebugMode = (process.env.NODE_ENV === 'debug');
let __ReactSightStore;
// TODO fix this garbage
var __ReactSightDebugMode = false;
let __ReactSightStore = [];

/** TODO - get objects to work
*
Expand Down Expand Up @@ -75,9 +78,16 @@ export const recur16 = (node, parentArr) => {
// get store
if (node.type && node.type.propTypes) {
if (node.type.propTypes.hasOwnProperty('store')) {
__ReactSightStore = node.stateNode.store.getState();
// TODO replace with safety check
try {
__ReactSightStore = node.stateNode.store.getState();
} catch (e) {
// noop
// console.log('Error getting store: ', e);
}
}
}

newComponent.children = [];
parentArr.push(newComponent);
if (node.child != null) recur16(node.child, newComponent.children);
Expand All @@ -101,13 +111,11 @@ export const traverse16 = (fiberDOM) => {
const components = [];
recur16(fiberDOM.current.stateNode.current, components);
if (__ReactSightDebugMode) console.log('[ReactSight] traverse16 data: ', components);
const data = {
data: components,
store: __ReactSightStore,
};
data.data = data.data[0].children[0].children;

const ReactSightData = { data: components, store: __ReactSightStore };
const clone = JSON.parse(JSON.stringify(ReactSightData));

const clone = JSON.parse(JSON.stringify(ReactSightData, circular()));

if (__ReactSightDebugMode) console.log('[ReactSight] retrieved data --> posting to content-scripts...: ', ReactSightData);
if (__ReactSightDebugMode) console.log('[ReactSight] SENDING -> ', clone);
window.postMessage(clone, '*');
Expand Down
3 changes: 3 additions & 0 deletions extension/backend/installHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { traverse16 } from './fiber-hook';
import { getData } from './react-15-hook';

// TODO fix this, I don't think node.process.env exits here, maybe need the define plugin
var __ReactSightDebugMode = (process.env.NODE_ENV === 'debug');

// Notes... might need additional testing..renderers provides a list of all imported React instances
Expand Down Expand Up @@ -45,6 +46,8 @@ if (!__ReactSightHasRun) {
if (instance && instance.version) {
__ReactSight_ReactVersion = instance.version;
if (__ReactSightDebugMode) console.log('version: ', __ReactSight_ReactVersion);

// onCommitFiberRoot
devTools.onCommitFiberRoot = (function (original) {
return function (...args) {
__ReactSightFiberDOM = args[1];
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"lint": "eslint extension",
"start": "webpack -w",
"start:debug": "NODE_ENV=debug webpack -w",
"test": "jest",
"coveralls": "NODE_PATH=. node_modules/.bin/jest && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"build": "webpack -p",
Expand All @@ -29,6 +30,7 @@
},
"homepage": "https://github.com/React-Sight/React-Sight#readme",
"dependencies": {
"circular": "^1.0.5",
"d3": "5.15.0",
"d3-interpolate": "1.4.0",
"json-formatter-js": "2.3.4",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,11 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
inherits "^2.0.1"
safe-buffer "^5.0.1"

circular@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/circular/-/circular-1.0.5.tgz#7da77af98bbde9ce4b5b358cd556b5dded2d3149"
integrity sha1-fad6+Yu96c5LWzWM1Va13e0tMUk=

class-utils@^0.3.5:
version "0.3.6"
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
Expand Down

0 comments on commit 1a5e676

Please sign in to comment.