Fix disabling a plugin nog clearing the message queue
Summary: While writing unit tests discovered a bug that disabling a plugin doesn't guarantee cleaning the messagequeues (both the buffer in client and the messagequeue reducer). Fixed that. That was thanks to @#%@#$@#%@ Redux a lot harder than it should be; as 'STAR_PLUGIN' reasons about a plugin + app name, while the message queue reducer would need to deduct the plugin keys from that, but it can't because that mapping is stored in the connections reducers. So I moved the `STAR_PLUGIN` action handling to the root reducer, sot that it can reason about the state of multiple reducers, which looked like the least of all evils. For more ranting about that and possible alternative solutions: https://twitter.com/mweststrate/status/1277556309706117122 Reviewed By: nikoant Differential Revision: D22284043 fbshipit-source-id: 35d0a8ba3a21a5959d2bb6ef17da3ff5077f48fd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bb0c8e0df0
commit
952e929699
@@ -135,6 +135,7 @@ export type Action =
|
||||
payload: number;
|
||||
}
|
||||
| {
|
||||
// Implemented by rootReducer in `store.tsx`
|
||||
type: 'STAR_PLUGIN';
|
||||
payload: {
|
||||
selectedApp: string;
|
||||
@@ -277,51 +278,6 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
|
||||
});
|
||||
}
|
||||
|
||||
case 'STAR_PLUGIN': {
|
||||
const {plugin, selectedApp} = action.payload;
|
||||
const selectedPlugin = plugin.id;
|
||||
const clients = state.clients.filter(
|
||||
(client) => client.query.app === selectedApp,
|
||||
);
|
||||
return produce(state, (draft) => {
|
||||
if (!draft.userStarredPlugins[selectedApp]) {
|
||||
draft.userStarredPlugins[selectedApp] = [];
|
||||
}
|
||||
const plugins = draft.userStarredPlugins[selectedApp];
|
||||
const idx = plugins.indexOf(selectedPlugin);
|
||||
if (idx === -1) {
|
||||
plugins.push(selectedPlugin);
|
||||
// enabling a plugin on one device enables it on all...
|
||||
clients.forEach((client) => {
|
||||
// sandy plugin? initialize it
|
||||
client.startPluginIfNeeded(plugin, true);
|
||||
// background plugin? connect it needed
|
||||
if (
|
||||
!defaultEnabledBackgroundPlugins.includes(selectedPlugin) &&
|
||||
client?.isBackgroundPlugin(selectedPlugin)
|
||||
) {
|
||||
client.initPlugin(selectedPlugin);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
plugins.splice(idx, 1);
|
||||
// enabling a plugin on one device disables it on all...
|
||||
clients.forEach((client) => {
|
||||
// disconnect background plugins
|
||||
if (
|
||||
!defaultEnabledBackgroundPlugins.includes(selectedPlugin) &&
|
||||
client?.isBackgroundPlugin(selectedPlugin)
|
||||
) {
|
||||
client.deinitPlugin(selectedPlugin);
|
||||
}
|
||||
// stop sandy plugins
|
||||
// TODO: forget any persisted state as well T68683449
|
||||
client.stopPluginIfNeeded(plugin.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
||||
const {payload} = action;
|
||||
return {...state, userPreferredPlugin: payload};
|
||||
|
||||
Reference in New Issue
Block a user