Fix persistedState bug
Summary: Persisted state was not being cleared across client disconnects. This fixes that. Reviewed By: passy Differential Revision: D16338524 fbshipit-source-id: ec51ec3bd999a388a0e8687f08841970872087ec
This commit is contained in:
committed by
Facebook Github Bot
parent
beb656c84e
commit
286f0d7acf
@@ -6,11 +6,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {default as reducer, setPluginState} from '../pluginStates';
|
import {default as reducer, setPluginState} from '../pluginStates';
|
||||||
|
import type {Action} from '../pluginStates';
|
||||||
|
|
||||||
test('reduce setPluginState', () => {
|
test('reduce setPluginState', () => {
|
||||||
const res = reducer(
|
const result = reducer(
|
||||||
{},
|
{},
|
||||||
setPluginState({pluginKey: 'myPlugin', state: {a: 1}}),
|
setPluginState({pluginKey: 'myPlugin', state: {a: 1}}),
|
||||||
);
|
);
|
||||||
expect(res).toEqual({myPlugin: {a: 1}});
|
expect(result).toEqual({myPlugin: {a: 1}});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CLEAR_PLUGIN_STATE removes plugin state', () => {
|
||||||
|
const clientId = 'app1#device1';
|
||||||
|
const pluginKey = 'app1#device1#plugin1';
|
||||||
|
|
||||||
|
const action: Action = {
|
||||||
|
type: 'CLEAR_PLUGIN_STATE',
|
||||||
|
payload: {id: clientId, devicePlugins: new Set()},
|
||||||
|
};
|
||||||
|
const result = reducer(
|
||||||
|
{[pluginKey]: {a: 1}, 'anotherPlugin#key': {b: 2}},
|
||||||
|
action,
|
||||||
|
);
|
||||||
|
expect(result).toEqual({'anotherPlugin#key': {b: 2}});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,8 +49,9 @@ export default function reducer(
|
|||||||
return Object.keys(state).reduce((newState, pluginKey) => {
|
return Object.keys(state).reduce((newState, pluginKey) => {
|
||||||
// Only add the pluginState, if its from a plugin other than the one that
|
// Only add the pluginState, if its from a plugin other than the one that
|
||||||
// was removed. pluginKeys are in the form of ${clientID}#${pluginID}.
|
// was removed. pluginKeys are in the form of ${clientID}#${pluginID}.
|
||||||
|
const clientId = pluginKey.slice(0, pluginKey.lastIndexOf('#'));
|
||||||
const pluginId = pluginKey.split('#').pop();
|
const pluginId = pluginKey.split('#').pop();
|
||||||
if (pluginId !== payload.id || payload.devicePlugins.has(pluginId)) {
|
if (clientId !== payload.id || payload.devicePlugins.has(pluginId)) {
|
||||||
newState[pluginKey] = state[pluginKey];
|
newState[pluginKey] = state[pluginKey];
|
||||||
}
|
}
|
||||||
return newState;
|
return newState;
|
||||||
|
|||||||
Reference in New Issue
Block a user