Command processing (1/n)

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*: implemented basic plugin action queue processing.

Reviewed By: mweststrate

Differential Revision: D26164945

fbshipit-source-id: 5d8ad9b4d7b1300e92883d24a71da9ca1f85b183
This commit is contained in:
Anton Nikolaev
2021-02-16 10:46:11 -08:00
committed by Facebook GitHub Bot
parent f10f963ff1
commit 8efdde08c4
5 changed files with 71 additions and 62 deletions

View File

@@ -53,7 +53,7 @@ import {ContentContainer} from './sandy-chrome/ContentContainer';
import {Alert, Typography} from 'antd';
import {InstalledPluginDetails} from 'plugin-lib';
import semver from 'semver';
import {activatePlugin} from './reducers/pluginManager';
import {loadPlugin} from './reducers/pluginManager';
import {produce} from 'immer';
import {reportUsage} from './utils/metrics';
@@ -129,7 +129,7 @@ type DispatchFromProps = {
setPluginState: (payload: {pluginKey: string; state: any}) => void;
setStaticView: (payload: StaticView) => void;
starPlugin: typeof starPlugin;
activatePlugin: typeof activatePlugin;
loadPlugin: typeof loadPlugin;
};
type Props = StateFromProps & DispatchFromProps & OwnProps;
@@ -381,7 +381,7 @@ class PluginContainer extends PureComponent<Props, State> {
}
reloadPlugin() {
const {activatePlugin, latestInstalledVersion} = this.props;
const {loadPlugin, latestInstalledVersion} = this.props;
if (latestInstalledVersion) {
reportUsage(
'plugin-auto-update:alert:reloadClicked',
@@ -390,7 +390,7 @@ class PluginContainer extends PureComponent<Props, State> {
},
latestInstalledVersion.id,
);
activatePlugin({
loadPlugin({
plugin: latestInstalledVersion,
enable: false,
notifyIfFailed: true,
@@ -619,6 +619,6 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
selectPlugin,
setStaticView,
starPlugin,
activatePlugin,
loadPlugin: loadPlugin,
},
)(PluginContainer);