Summary: This is purely refactoring change. Before that we computed plugin lists in-place in PluginList component. Now we will be re-computing them as side effect and will keep computed lists in redux. This makes it easier to re-use plugin lists in other places outside of PluginList component, e.g. in the upcoming Marketplace UI. Reviewed By: mweststrate Differential Revision: D29161719 fbshipit-source-id: 5cb06d4d8a553aa856101c78b2311fbc078c6bd7
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import {
|
|
PluginDetails,
|
|
DownloadablePluginDetails,
|
|
BundledPluginDetails,
|
|
} from 'flipper-plugin-lib';
|
|
import {Actions} from '.';
|
|
import {
|
|
DevicePluginDefinition,
|
|
ClientPluginDefinition,
|
|
PluginDefinition,
|
|
} from '../plugin';
|
|
import produce from 'immer';
|
|
|
|
export type State = {
|
|
devicePlugins: DevicePluginDefinition[];
|
|
metroPlugins: DevicePluginDefinition[];
|
|
enabledPlugins: ClientPluginDefinition[];
|
|
disabledPlugins: PluginDefinition[];
|
|
unavailablePlugins: [plugin: PluginDetails, reason: string][];
|
|
downloadablePlugins: (DownloadablePluginDetails | BundledPluginDetails)[];
|
|
};
|
|
|
|
const INITIAL_STATE: State = {
|
|
devicePlugins: [],
|
|
metroPlugins: [],
|
|
enabledPlugins: [],
|
|
disabledPlugins: [],
|
|
unavailablePlugins: [],
|
|
downloadablePlugins: [],
|
|
};
|
|
|
|
export type Action = {
|
|
type: 'PLUGIN_LISTS_CHANGED';
|
|
payload: State;
|
|
};
|
|
|
|
export default function reducer(
|
|
state: State | undefined = INITIAL_STATE,
|
|
action: Actions,
|
|
): State {
|
|
if (action.type === 'PLUGIN_LISTS_CHANGED') {
|
|
const payload = action.payload;
|
|
return produce(state, (draft) => {
|
|
draft.devicePlugins = payload.devicePlugins;
|
|
draft.metroPlugins = payload.metroPlugins;
|
|
draft.enabledPlugins = payload.enabledPlugins;
|
|
draft.disabledPlugins = payload.disabledPlugins;
|
|
draft.unavailablePlugins = payload.unavailablePlugins;
|
|
draft.downloadablePlugins = payload.downloadablePlugins;
|
|
});
|
|
} else {
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export const pluginListsChanged = (payload: State): Action => ({
|
|
type: 'PLUGIN_LISTS_CHANGED',
|
|
payload,
|
|
});
|