Skip to content

Commit 64b0cb5

Browse files
committed
imporve popup data flow
1 parent 31b7f9d commit 64b0cb5

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

extensions/chrome/background/background.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ chrome.runtime.onConnect.addListener(port => {
88
if (message.type === "REACT_CONTEXT_DEVTOOL_INIT") {
99
connections[message.tabId] = port;
1010
if (catchData[message.tabId]) {
11-
port.postMessage(getCatchData(message.tabId));
11+
port.postMessage({
12+
type: 'REACT_CONTEXT_DEVTOOL_DEVPANEL_DATA',
13+
data: getCatchData(message.tabId),
14+
});
1215
}
1316
return;
1417
}
@@ -39,29 +42,39 @@ chrome.tabs.onRemoved.addListener(tabId => {
3942
chrome.runtime.onMessage.addListener((request, sender) => {
4043
if (request.type === 'REACT_CONTEXT_DEVTOOL_DETECTED') {
4144
setAppPopup(true, sender.tab.id);
42-
return;
45+
return true;
4346
}
4447

4548
if (request.type === 'REACT_CONTEXT_DEVTOOL_POPUP_DATA_REQUEST') {
46-
chrome.runtime.sendMessage({
47-
type: 'REACT_CONTEXT_DEVTOOL_POPUP_DATA',
48-
data: getCatchData(request.tabId),
49-
});
49+
sendMessageToPopup(request.tabId);
5050
return true;
5151
}
5252
if (request.type === 'REACT_CONTEXT_DEVTOOL_DATA' && sender.tab) {
5353
const tabId = sender.tab.id;
5454
saveCatchData(request.data, sender.tab);
55-
if (tabId in connections) {
56-
connections[tabId].postMessage({
57-
type: 'REACT_CONTEXT_DEVTOOL_DEVPANEL_DATA',
58-
data: getCatchData(tabId),
59-
});
60-
}
55+
sendMessageToDevPanel(tabId);
56+
sendMessageToPopup(tabId);
6157
}
6258
return true;
6359
});
6460

61+
const sendMessageToPopup = tabId => {
62+
chrome.runtime.sendMessage({
63+
type: 'REACT_CONTEXT_DEVTOOL_POPUP_DATA',
64+
data: getCatchData(tabId),
65+
tabId,
66+
});
67+
};
68+
69+
const sendMessageToDevPanel = tabId => {
70+
if (tabId in connections) {
71+
connections[tabId].postMessage({
72+
type: 'REACT_CONTEXT_DEVTOOL_DEVPANEL_DATA',
73+
data: getCatchData(tabId),
74+
});
75+
}
76+
};
77+
6578
const saveCatchData = (dataToCatch, { id: tabId, title }) => {
6679
if (!catchData[tabId]) {
6780
catchData[tabId] = {
@@ -84,8 +97,6 @@ const saveCatchData = (dataToCatch, { id: tabId, title }) => {
8497

8598
catchData[tabId].context[id].oldValue = catchData[tabId].context[id].newValue;
8699
catchData[tabId].context[id].newValue = dataToCatch;
87-
88-
console.log(catchData);
89100
};
90101

91102
const getCatchData = tabId => {

src/components/DiffView/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const DiffView = ({ oldValue, data }) => {
3030
splitView={false}
3131
hideLineNumbers
3232
styles={newStyles}
33-
extraLinesSurroundingDiff={Infinity}
33+
extraLinesSurroundingDiff={500}
3434
renderContent={highlightSyntax}
3535
/>
3636
</DiffViewWrapper>

src/devpanel.index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const DevPanel = () => {
2727

2828
const onMessage = message => {
2929
if (message.type === 'REACT_CONTEXT_DEVTOOL_DEVPANEL_DATA') {
30-
console.log("message from devpanel", message);
3130
setAppData(message.data);
3231
}
3332
};

src/popup.index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import ReactDOM from "react-dom";
55
import App from "./App";
66

77
const registerTab = onMessage => {
8+
let tabId = null;
9+
810
chrome.runtime.onMessage.addListener(function(message) {
9-
console.log(message);
10-
if (message.type === "REACT_CONTEXT_DEVTOOL_POPUP_DATA") {
11+
if (
12+
message.type === "REACT_CONTEXT_DEVTOOL_POPUP_DATA" &&
13+
tabId &&
14+
tabId === message.tabId
15+
) {
1116
onMessage(message.data);
1217
}
1318
});
1419

1520
chrome.tabs.query({ active: true, currentWindow: true }, tab => {
21+
tabId = tab[0].id;
1622
chrome.runtime.sendMessage({
17-
type: 'REACT_CONTEXT_DEVTOOL_POPUP_DATA_REQUEST',
18-
tabId: tab[0].id
19-
})
23+
type: "REACT_CONTEXT_DEVTOOL_POPUP_DATA_REQUEST",
24+
tabId
25+
});
2026
});
2127
};
2228

@@ -28,7 +34,6 @@ const DevPanel = () => {
2834
}, []);
2935

3036
const onMessage = message => {
31-
console.log("message from popup", message);
3237
setAppData(message);
3338
};
3439

0 commit comments

Comments
 (0)