Skip to content

Commit 2fb9e55

Browse files
committed
Merge branch 'dev' into josh/contextmenu
2 parents da659c8 + 42ef218 commit 2fb9e55

File tree

5 files changed

+63
-48
lines changed

5 files changed

+63
-48
lines changed

package/timeJump.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable no-param-reassign */
12
// traverses given tree by accessing children through coords array
23
function traverseTree(tree, coords) {
34
let curr = tree;
4-
coords.forEach((coord) => {
5+
coords.forEach(coord => {
56
curr = curr.children[coord];
67
});
78
return curr;
@@ -21,8 +22,7 @@ module.exports = (origin, mode) => {
2122
});
2223
}
2324

24-
25-
return (target) => {
25+
return target => {
2626
// setting mode disables setState from posting messages to window
2727
mode.jumping = true;
2828
jump(target);

src/app/components/SwitchApp.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SwitchAppDropdown = () => {
99
const tabsArray = [];
1010

1111
Object.keys(tabs).forEach(tab => {
12-
if (tab !== 'sourceTab') tabsArray.push({ value: tab, label: tabs[tab].title });
12+
tabsArray.push({ value: tab, label: tabs[tab].title });
1313
});
1414

1515
const currTab = {

src/app/containers/MainContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ function MainContainer() {
2424

2525
// listen for a message containing snapshots from the background script
2626
port.onMessage.addListener(message => {
27-
const { action, payload } = message;
27+
const { action, payload, sourceTab } = message;
2828
switch (action) {
2929
case 'deleteTab': {
3030
dispatch(deleteTab(payload));
3131
break;
3232
}
3333

3434
case 'sendSnapshots': {
35-
if (payload.sourceTab !== currentTab) dispatch(setTab(payload.sourceTab));
35+
dispatch(setTab(sourceTab));
3636
// set state with the information received from the background script
3737
dispatch(addNewSnapshots(payload));
3838
break;

src/app/reducers/mainReducer.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,46 +111,40 @@ export default (state, action) => produce(state, draft => {
111111
const { payload } = action;
112112
Object.keys(payload).forEach(tab => {
113113
// check if tab exists in memory
114-
if (!tabs[tab]) {
115-
// add new tab
116-
tabs[tab] = {
117-
...payload[tab],
118-
sliderIndex: 0,
119-
viewIndex: -1,
120-
intervalId: null,
121-
playing: false,
122-
};
123-
}
114+
// add new tab
115+
tabs[tab] = {
116+
...payload[tab],
117+
sliderIndex: 0,
118+
viewIndex: -1,
119+
intervalId: null,
120+
playing: false,
121+
};
124122
});
125123

126124
// only set first tab if current tab is non existent
127125
const firstTab = parseInt(Object.keys(payload)[0], 10);
128-
draft.currentTab = currentTab === null ? firstTab : currentTab;
129-
126+
if (currentTab === undefined || currentTab === null) draft.currentTab = firstTab;
130127
break;
131128
}
132129
case types.NEW_SNAPSHOTS: {
133130
const { payload } = action;
134131

135132
Object.keys(tabs).forEach(tab => {
136-
if (tab !== 'sourceTab') {
137-
if (!payload[tab]) {
138-
delete tabs[tab];
139-
} else {
140-
const { snapshots: newSnaps } = payload[tab];
141-
tabs[tab] = {
142-
...tabs[tab],
143-
...payload[tab],
144-
sliderIndex: newSnaps.length - 1,
145-
};
146-
}
133+
if (!payload[tab]) {
134+
delete tabs[tab];
135+
} else {
136+
const { snapshots: newSnaps } = payload[tab];
137+
tabs[tab] = {
138+
...tabs[tab],
139+
...payload[tab],
140+
sliderIndex: newSnaps.length - 1,
141+
};
147142
}
148143
});
149144

150145
// only set first tab if current tab is non existent
151146
const firstTab = parseInt(Object.keys(payload)[0], 10);
152-
draft.currentTab = currentTab === null ? firstTab : currentTab;
153-
147+
if (currentTab === undefined || currentTab === null) draft.currentTab = firstTab;
154148
break;
155149
}
156150
case types.SET_TAB: {
@@ -162,7 +156,7 @@ export default (state, action) => produce(state, draft => {
162156
if (draft.currentTab === action.payload) {
163157
// if the deleted tab was set to currentTab, replace currentTab with
164158
// the first tabId within tabs obj
165-
const newCurrentTab = Object.keys(draft.tabs)[0];
159+
const newCurrentTab = parseInt(Object.keys(draft.tabs)[0], 10);
166160
draft.currentTab = newCurrentTab;
167161
}
168162
break;

src/extension/background.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const portsArr = [];
21
// store ports in an array
3-
const tabsObj = {
4-
sourceTab: null,
5-
};
2+
const portsArr = [];
3+
const reloaded = {};
4+
const firstSnapshotReceived = {};
5+
const tabsObj = {};
66

77
function createTabObj(title) {
88
return {
@@ -13,7 +13,6 @@ function createTabObj(title) {
1313
locked: false,
1414
paused: false,
1515
},
16-
firstSnapshot: true,
1716
};
1817
}
1918

@@ -86,7 +85,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
8685
// Filter out tabs that don't have react-time-travel
8786
if (action === 'tabReload' || action === 'recordSnap') {
8887
isReactTimeTravel = true;
89-
}
88+
} else return;
9089

9190
// everytime we get a new tabid, add it to the object
9291
if (isReactTimeTravel && !(tabId in tabsObj)) {
@@ -96,17 +95,33 @@ chrome.runtime.onMessage.addListener((request, sender) => {
9695
const { persist } = tabsObj[tabId].mode;
9796

9897
switch (action) {
99-
case 'tabReload':
100-
tabsObj[tabId].firstSnapshot = true;
98+
case 'tabReload': {
10199
tabsObj[tabId].mode.locked = false;
102100
tabsObj[tabId].mode.paused = false;
103-
if (!persist) tabsObj[tabId].snapshots = [];
101+
// dont remove snapshots if persisting
102+
if (!persist) {
103+
tabsObj[tabId].snapshots.splice(1);
104+
105+
// send a message to devtools
106+
portsArr.forEach(bg => bg.postMessage({
107+
action: 'initialConnectSnapshots',
108+
payload: tabsObj,
109+
}));
110+
}
111+
112+
reloaded[tabId] = true;
113+
104114
break;
105-
case 'recordSnap':
106-
if (tabsObj[tabId].firstSnapshot) {
107-
tabsObj[tabId].firstSnapshot = false;
108-
// don't add anything to snapshot storage if mode is persisting for the initial snapshot
109-
if (!persist) tabsObj[tabId].snapshots.push(request.payload);
115+
}
116+
case 'recordSnap': {
117+
const sourceTab = tabId;
118+
119+
// first snapshot received from tab
120+
if (!firstSnapshotReceived[tabId]) {
121+
firstSnapshotReceived[tabId] = true;
122+
reloaded[tabId] = false;
123+
124+
tabsObj[tabId].snapshots.push(request.payload);
110125
if (portsArr.length > 0) {
111126
portsArr.forEach(bg => bg.postMessage({
112127
action: 'initialConnectSnapshots',
@@ -116,17 +131,21 @@ chrome.runtime.onMessage.addListener((request, sender) => {
116131
break;
117132
}
118133

119-
tabsObj[tabId].snapshots.push(request.payload);
120-
tabsObj.sourceTab = tabId;
134+
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
135+
if (reloaded[tabId]) {
136+
reloaded[tabId] = false;
137+
} else tabsObj[tabId].snapshots.push(request.payload);
121138

122139
// send message to devtools
123140
if (portsArr.length > 0) {
124141
portsArr.forEach(bg => bg.postMessage({
125142
action: 'sendSnapshots',
126143
payload: tabsObj,
144+
sourceTab,
127145
}));
128146
}
129147
break;
148+
}
130149
default:
131150
break;
132151
}
@@ -144,6 +163,8 @@ chrome.tabs.onRemoved.addListener(tabId => {
144163

145164
// delete the tab from the tabsObj
146165
delete tabsObj[tabId];
166+
delete reloaded[tabId];
167+
delete firstSnapshotReceived[tabId];
147168
});
148169

149170
// when react time travel is installed

0 commit comments

Comments
 (0)