@@ -71,7 +71,11 @@ class App extends Component {
71
71
// adds listener to the effects that are gonna be sent from
72
72
// our edited useReducer from the 'react' library.
73
73
chrome . runtime . onConnect . addListener ( ( port ) => {
74
- if ( port . name !== 'injected-app' ) return ;
74
+ // if our port is already open with the extension script,
75
+ // we don't want to change this.portToExtension no more. We want
76
+ // to keep every instance of the App associated with the specific
77
+ // extension script that can communicated with the injected timeTravel.
78
+ if ( port . name !== 'injected-app' || this . portToExtension ) return ;
75
79
76
80
this . portToExtension = port ;
77
81
@@ -90,11 +94,10 @@ class App extends Component {
90
94
// search field
91
95
const { searchField } = this . state ;
92
96
const newDataActionType = newData . action . type . toLowerCase ( ) ;
93
-
94
- // get the date everytime an action fires and add it to state
95
97
96
98
const eventTime = Date . now ( ) ;
97
-
99
+
100
+ // get the date everytime an action fires and add it to state
98
101
if ( newDataActionType . includes ( searchField . toLowerCase ( ) ) ) {
99
102
this . setState ( state => ( {
100
103
data : [ ...state . data , newData ] ,
@@ -140,18 +143,18 @@ class App extends Component {
140
143
}
141
144
142
145
setIsRecording ( ) {
143
- // This variable will prevent the app from refreshing when we refresh
144
- // the userpage.
145
- this . justStartedRecording = true ;
146
- const { isRecording, hasInjectedScript } = this . state ;
146
+ const { isRecording } = this . state ;
147
147
this . setState ( state => ( {
148
148
isRecording : ! state . isRecording ,
149
149
} ) ) ;
150
150
151
151
// if we are hitting the pause or re-starting the record session
152
- if ( isRecording || hasInjectedScript ) return ;
152
+ if ( isRecording || this . hasInjectedScript ) return ;
153
153
154
- this . setState ( { hasInjectedScript : true } ) ;
154
+ // This variable will prevent the app from refreshing when we refresh
155
+ // the userpage.
156
+ this . justStartedRecording = true ;
157
+ this . hasInjectedScript = true ;
155
158
156
159
// we query the active window so we can send it to the background script
157
160
// so it knows on which URL to run our devtool.
@@ -167,11 +170,13 @@ class App extends Component {
167
170
}
168
171
169
172
actionInPlay ( ) {
170
- const { data, isPlayingIndex, isPlaying } = this . state ;
173
+ const { data, isPlayingIndex } = this . state ;
171
174
172
175
setTimeout ( ( ) => {
173
176
this . toTheFuture ( ) ;
174
- if ( isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
177
+ // We CANT deconstruct isPlaying because we want it to be the value
178
+ // when this function gets executed - 1000s later.
179
+ if ( this . state . isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
175
180
this . actionInPlay ( ) ;
176
181
} else {
177
182
this . setState ( { isPlaying : false } ) ;
@@ -260,6 +265,7 @@ class App extends Component {
260
265
if ( isPlayingIndex === 0 ) return ;
261
266
262
267
if ( ! this . portToExtension ) return console . error ( 'No connection on stored port.' ) ;
268
+
263
269
this . portToExtension . postMessage ( {
264
270
type : 'TIMETRAVEL' ,
265
271
direction : 'backwards' ,
@@ -278,11 +284,13 @@ class App extends Component {
278
284
279
285
resetApp ( ) {
280
286
if ( this . justStartedRecording ) {
281
- console . log ( 'not reseting...' ) ;
282
- this . justStartedRecording = false ;
287
+ // hacky: some pages will fire update twice on the background script
288
+ setTimeout ( ( ) => this . justStartedRecording = false , 50 ) ;
283
289
return ;
284
290
}
285
- console . log ( 'reseting...' ) ;
291
+
292
+ this . justStartedRecording = false ;
293
+ this . hasInjectedScript = false ;
286
294
this . setState ( {
287
295
data : [ ] ,
288
296
searchField : '' ,
@@ -294,6 +302,7 @@ class App extends Component {
294
302
action : { } ,
295
303
state : { } ,
296
304
prevState : { } ,
305
+ eventTimes : [ ] ,
297
306
} ) ;
298
307
}
299
308
0 commit comments