Skip to content

Commit 44fb14f

Browse files
committed
changed TreeContainer to a functional component Tree.jsx
1 parent 52ba77b commit 44fb14f

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/app/components/Tree.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import JSONTree from 'react-json-tree';
3+
4+
const getItemString = (type, data, itemType, itemString) => (
5+
<span>
6+
//
7+
{type}
8+
</span>
9+
);
10+
11+
const Tree = (props) => {
12+
const { snapshot } = props;
13+
return (
14+
<JSONTree
15+
data={snapshot}
16+
theme={{ tree: () => ({ className: 'json-tree' }) }}
17+
getItemString={getItemString}
18+
/>
19+
);
20+
};
21+
export default Tree;

src/app/containers/StateContainer.jsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
2-
import JSONTree from 'react-json-tree';
32
import * as themes from 'redux-devtools-themes';
3+
import Tree from '../components/Tree';
44

55
const getItemString = (type, data, itemType, itemString) => (
66
<span>
@@ -17,17 +17,7 @@ class StateContainer extends Component {
1717

1818
render() {
1919
const { snapshot } = this.props;
20-
return (
21-
<div className="state-container">
22-
{snapshot && (
23-
<JSONTree
24-
data={snapshot}
25-
theme={{ tree: () => ({ className: 'json-tree' }) }}
26-
getItemString={getItemString}
27-
/>
28-
)}
29-
</div>
30-
);
20+
return <div className="state-container">{snapshot && <Tree snapshot={snapshot} />}</div>;
3121
}
3222
}
3323

src/extension/background.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
console.log('background.js file is running');
22

33
let bg;
4-
5-
// when tab refreshes, empty snapshotArr
6-
7-
// need a function to clear snapshotArr when either tab is closed or page is refreshed
84
let snapshotArr = [];
95

106
// establishing connection with devtools
@@ -34,17 +30,11 @@ chrome.runtime.onConnect.addListener((port) => {
3430

3531
// background.js recieves message from contentScript.js
3632
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
37-
console.log('npm -> background', request);
38-
// if port is not null, send a message to devtools
39-
40-
if (request.action === 'tabReload') {
41-
console.log('tabReload');
42-
snapshotArr = [];
43-
}
33+
if (request.action === 'tabReload') snapshotArr = [];
4434

45-
console.log(request);
4635
if (request.action === 'recordSnap') {
4736
snapshotArr.push(request.payload);
37+
// if port is not null, send a message to devtools
4838
if (bg) {
4939
// get active tab id
5040
// get snapshot arr from tab object

0 commit comments

Comments
 (0)