Command processing (3/n): Uninstall plugin
Summary: *Stack summary*: this stack refactors plugin management actions to perform them in a dispatcher rather than in the root reducer (store.tsx) as all of these actions has side effects. To do that, we store requested plugin management actions (install/update/uninstall, star/unstar) in a queue which is then handled by pluginManager dispatcher. This dispatcher then dispatches all required state updates. *Diff summary*: refactored "uninstall plugin" operation to perform it in pluginManager dispatcher Reviewed By: mweststrate Differential Revision: D26166198 fbshipit-source-id: d74a1d690102d9036c6d3d8612d2428f5ecef4e6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
24aed8fd45
commit
01f02b2cab
@@ -84,9 +84,6 @@ export function rootReducer(
|
||||
} else {
|
||||
return updateClientPlugin(state, plugin, enablePlugin);
|
||||
}
|
||||
} else if (action.type === 'UNINSTALL_PLUGIN' && state) {
|
||||
const plugin = action.payload;
|
||||
return uninstallPlugin(state, plugin);
|
||||
}
|
||||
|
||||
// otherwise
|
||||
@@ -184,27 +181,6 @@ function updateClientPlugin(
|
||||
});
|
||||
}
|
||||
|
||||
function uninstallPlugin(state: StoreState, plugin: PluginDefinition) {
|
||||
const clients = state.connections.clients;
|
||||
return produce(state, (draft) => {
|
||||
clients.forEach((client) => {
|
||||
stopPlugin(client, plugin.id);
|
||||
const pluginKey = getPluginKey(
|
||||
client.id,
|
||||
{serial: client.query.device_id},
|
||||
plugin.id,
|
||||
);
|
||||
delete draft.pluginMessageQueue[pluginKey];
|
||||
});
|
||||
cleanupPluginStates(draft.pluginStates, plugin.id);
|
||||
unloadPluginModule(plugin.details);
|
||||
draft.plugins.clientPlugins.delete(plugin.id);
|
||||
draft.plugins.devicePlugins.delete(plugin.id);
|
||||
draft.plugins.loadedPlugins.delete(plugin.id);
|
||||
draft.pluginManager.uninstalledPlugins.add(plugin.details.name);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDevicePlugin(state: StoreState, plugin: DevicePluginDefinition) {
|
||||
const devices = state.connections.devices;
|
||||
return produce(state, (draft) => {
|
||||
@@ -235,7 +211,7 @@ function registerLoadedPlugin(
|
||||
},
|
||||
plugin: ActivatablePluginDetails,
|
||||
) {
|
||||
draft.pluginManager.uninstalledPlugins.delete(plugin.name);
|
||||
draft.plugins.uninstalledPlugins.delete(plugin.name);
|
||||
draft.plugins.loadedPlugins.set(plugin.id, plugin);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user