Skip to content

Commit 417a775

Browse files
committed
added persist button functionality on backend
1 parent 9731548 commit 417a775

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

package/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const snapShot = { tree: null };
22

3-
const mode = { jumping: false, paused: false, locked: false };
3+
const mode = {
4+
jumping: false, paused: false, locked: false,
5+
};
46

57
const linkFiber = require('./linkFiber')(snapShot, mode);
68
const timeJump = require('./timeJump')(snapShot, mode);

src/app/containers/MainContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class MainContainer extends Component {
120120
mode.locked = !locked;
121121
break;
122122
case 'persist':
123-
port.postMessage({ action: 'setPersist', payload: !locked });
123+
port.postMessage({ action: 'setPersist', payload: !persist });
124124
mode.persist = !persist;
125125
break;
126126
default:

src/extension/background.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mode = {
55
locked: false,
66
paused: false,
77
};
8+
let firstSnapshot = true;
89

910
// establishing connection with devtools
1011
chrome.runtime.onConnect.addListener((port) => {
@@ -50,21 +51,35 @@ chrome.runtime.onConnect.addListener((port) => {
5051

5152
// background.js recieves message from contentScript.js
5253
chrome.runtime.onMessage.addListener((request) => {
53-
if (request.action === 'tabReload') snapshotArr = [];
54+
const { action } = request;
55+
const { persist } = mode;
5456

55-
if (request.action === 'recordSnap') {
56-
snapshotArr.push(request.payload);
57-
// if port is not null, send a message to devtools
58-
if (bg) {
59-
// TODO:
60-
// get active tab id
61-
// get snapshot arr from tab object
57+
switch (action) {
58+
case 'tabReload':
59+
firstSnapshot = true;
60+
if (!persist) snapshotArr = [];
61+
break;
62+
case 'recordSnap':
63+
// don't do anything for the first snapshot if current mode is persist
64+
if (persist && firstSnapshot) {
65+
firstSnapshot = false;
66+
break;
67+
}
68+
firstSnapshot = false;
69+
snapshotArr.push(request.payload);
70+
// if port is not null, send a message to devtools
71+
if (bg) {
72+
// TODO:
73+
// get active tab id
74+
// get snapshot arr from tab object
6275

63-
// send message to devtools
64-
bg.postMessage({
65-
action: 'sendSnapshots',
66-
payload: snapshotArr,
67-
});
68-
}
76+
// send message to devtools
77+
bg.postMessage({
78+
action: 'sendSnapshots',
79+
payload: snapshotArr,
80+
});
81+
}
82+
break;
83+
default:
6984
}
7085
});

0 commit comments

Comments
 (0)