diff --git a/src/dispatcher/server.js b/src/dispatcher/server.js index 8eab4b1cf..dda29807d 100644 --- a/src/dispatcher/server.js +++ b/src/dispatcher/server.js @@ -26,6 +26,10 @@ export default (store: Store, logger: Logger) => { type: 'CLIENT_REMOVED', payload: id, }); + store.dispatch({ + type: 'CLEAR_PLUGIN_STATE', + payload: id, + }); }); server.addListener('error', err => { diff --git a/src/reducers/pluginStates.js b/src/reducers/pluginStates.js index c264d255c..0c249da37 100644 --- a/src/reducers/pluginStates.js +++ b/src/reducers/pluginStates.js @@ -9,13 +9,18 @@ export type State = { [pluginKey: string]: Object, }; -export type Action = { - type: 'SET_PLUGIN_STATE', - payload: { - pluginKey: string, - state: Object, - }, -}; +export type Action = + | { + type: 'SET_PLUGIN_STATE', + payload: { + pluginKey: string, + state: Object, + }, + } + | { + type: 'CLEAR_PLUGIN_STATE', + payload: string, + }; const INITIAL_STATE: State = {}; @@ -31,6 +36,16 @@ export default function reducer( ...action.payload.state, }, }; + } else if (action.type === 'CLEAR_PLUGIN_STATE') { + const {payload} = action; + return Object.keys(state).reduce((newState, pluginKey) => { + // Only add the pluginState, if its from a plugin other than the one that + // was removed. pluginKeys are in the form of ${clientID}#${pluginID}. + if (!pluginKey.startsWith(payload)) { + newState[pluginKey] = state[pluginKey]; + } + return newState; + }, {}); } else { return state; }