Fixed broken navigation plugin

Summary: The navigation plugin threw exceptions, as the defaultPersisted state was not mixed into the already stored state, making some fields unreadable

Reviewed By: jknoxville

Differential Revision: D19554291

fbshipit-source-id: 57f045aa1eae10682e44d479b9aecb51f0391b9e
This commit is contained in:
Michel Weststrate
2020-01-27 04:02:24 -08:00
committed by Facebook Github Bot
parent 23625f7a89
commit e9ff9addc6
3 changed files with 19 additions and 10 deletions

View File

@@ -8,7 +8,7 @@
* @flow strict-local
*/
import {FlipperPlugin, bufferToBlob, FlexColumn} from 'flipper';
import {FlipperPlugin, FlexColumn, bufferToBlob} from 'flipper';
import {
BookmarksSidebar,
SaveBookmarkDialog,

View File

@@ -143,10 +143,7 @@ export function processMessageImmediately(
},
message: {method: string; params?: any},
) {
const persistedState: any =
store.getState().pluginStates[pluginKey] ??
plugin.defaultPersistedState ??
{};
const persistedState = getCurrentPluginState(store, plugin, pluginKey);
const newPluginState = processMessage(
persistedState,
pluginKey,
@@ -217,10 +214,7 @@ export async function processMessageQueue(
break;
}
// there are messages to process! lets do so until we have to idle
const persistedState =
store.getState().pluginStates[pluginKey] ??
plugin.defaultPersistedState ??
{};
const persistedState = getCurrentPluginState(store, plugin, pluginKey);
let offset = 0;
let newPluginState = persistedState;
do {
@@ -267,3 +261,15 @@ function getPendingMessages(
): Message[] {
return store.getState().pluginMessageQueue[pluginKey] || [];
}
function getCurrentPluginState(
store: MiddlewareAPI,
plugin: {defaultPersistedState: any},
pluginKey: string,
) {
// possible optimization: don't spread default state here by put proper default state when initializing clients
return {
...plugin.defaultPersistedState,
...store.getState().pluginStates[pluginKey],
};
}

View File

@@ -346,5 +346,8 @@
],
"app-react-outline": [
16
],
"send-outline": [
16
]
}