Command processing (5/n): Star 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 "star plugin" operation to perform it in pluginManager dispatcher.

Reviewed By: mweststrate

Differential Revision: D26305576

fbshipit-source-id: 90516af4e9ba8504720ddfa587f691f53e71b702
This commit is contained in:
Anton Nikolaev
2021-02-16 10:46:11 -08:00
committed by Facebook GitHub Bot
parent 0b803f810e
commit 19f2fccc79
15 changed files with 156 additions and 131 deletions

View File

@@ -108,24 +108,18 @@ export type Action =
payload: StaticView;
deepLinkPayload: unknown;
}
| {
// Implemented by rootReducer in `store.tsx`
type: 'STAR_PLUGIN';
payload: {
selectedApp: string;
plugin: PluginDefinition;
};
}
| {
type: 'PLUGIN_STARRED';
payload: {
plugin: PluginDefinition;
selectedApp: string;
};
}
| {
type: 'PLUGIN_UNSTARRED';
payload: {
plugin: PluginDefinition;
selectedApp: string;
};
}
| {
@@ -372,14 +366,8 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
return state;
}
case 'PLUGIN_STARRED': {
const {plugin} = action.payload;
const {plugin, selectedApp} = action.payload;
const selectedPlugin = plugin.id;
const selectedApp = state.selectedApp
? deconstructClientId(state.selectedApp).app
: undefined;
if (!selectedApp) {
return state;
}
return produce(state, (draft) => {
if (!draft.userStarredPlugins[selectedApp]) {
draft.userStarredPlugins[selectedApp] = [];
@@ -392,12 +380,8 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
});
}
case 'PLUGIN_UNSTARRED': {
const {plugin} = action.payload;
const {plugin, selectedApp} = action.payload;
const selectedPlugin = plugin.id;
const selectedApp = state.selectedApp;
if (!selectedApp) {
return state;
}
return produce(state, (draft) => {
if (!draft.userStarredPlugins[selectedApp]) {
draft.userStarredPlugins[selectedApp] = [];
@@ -449,30 +433,30 @@ export const selectPlugin = (payload: {
payload: {...payload, time: payload.time ?? Date.now()},
});
export const starPlugin = (payload: {
plugin: PluginDefinition;
selectedApp: string;
}): Action => ({
type: 'STAR_PLUGIN',
payload,
});
export const selectClient = (clientId: string | null): Action => ({
type: 'SELECT_CLIENT',
payload: clientId,
});
export const pluginStarred = (plugin: PluginDefinition): Action => ({
export const pluginStarred = (
plugin: PluginDefinition,
appId: string,
): Action => ({
type: 'PLUGIN_STARRED',
payload: {
plugin,
selectedApp: appId,
},
});
export const pluginUnstarred = (plugin: PluginDefinition): Action => ({
export const pluginUnstarred = (
plugin: PluginDefinition,
appId: string,
): Action => ({
type: 'PLUGIN_UNSTARRED',
payload: {
plugin,
selectedApp: appId,
},
});