Skip to content

Commit

Permalink
fix(devtools): time travel causes app to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
pac-guerreiro committed Aug 28, 2023
1 parent 87a4f70 commit 9139a1f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
9 changes: 2 additions & 7 deletions lib/DevTools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {connectViaExtension, extractState} from 'remotedev';
import {connectViaExtension} from 'remotedev';
import _ from 'underscore';

class DevTools {
Expand All @@ -12,15 +12,10 @@ class DevTools {
* @param {object} initialState - initial state of the storage
* @param {onStateChange} onStateChange - callback which is triggered when we timetravel to a different registered action
*/
constructor(initialState = {}, onStateChange = () => {}) {
constructor(initialState = {}) {
this.state = initialState;
this.onStateChange = onStateChange;
this.remotedev = connectViaExtension();
this.remotedev.init(this.state);
this.remotedev.subscribe((message) => {
const state = extractState(message);
this.onStateChange(state);
});
}

/**
Expand Down
22 changes: 1 addition & 21 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,27 +1144,7 @@ function initializeWithDefaultKeyStates(enableDevTools = false) {
cache.merge(merged);
_.each(merged, (val, key) => keyChanged(key, val));
if (enableDevTools) {
devTools = new DevTools(merged, (state) => {
Storage.getAllKeys().then((currentKeys) => {
const newState = state;
const newKeys = _.keys(state);
const removedKeys = _.without(_.values(currentKeys), newKeys);

// Remove keys that dont exist in the new state
_.each(removedKeys, (value, key) => {
newState[key] = undefined;
});

// Update cache and optimistically inform subscribers on the next tick
_.each(newState, (value, key) => {
cache.set(key, value);
notifySubscribersOnNextTick(key, value);
});

// Update existing keys
Storage.multiSet(prepareKeyValuePairsForStorage(newState));
});
});
devTools = new DevTools(merged);
}
});
}
Expand Down

0 comments on commit 9139a1f

Please sign in to comment.