Summary: In order to have update notifications, this must live outside the UI component, but it also gives some additional benefits like better testability of previously effectful UI. Reviewed By: jknoxville Differential Revision: D18173166 fbshipit-source-id: 1cacb6c7893423a7920a6620dfb76e631caba101
51 lines
983 B
TypeScript
51 lines
983 B
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 {Actions} from './';
|
|
|
|
export type PluginDefinition = {
|
|
name: string;
|
|
version: string;
|
|
description: string;
|
|
};
|
|
|
|
export type PluginMap = Map<string, PluginDefinition>;
|
|
|
|
export type State = {
|
|
installedPlugins: PluginMap;
|
|
};
|
|
|
|
export type Action = {
|
|
type: 'REGISTER_INSTALLED_PLUGINS';
|
|
payload: PluginMap;
|
|
};
|
|
|
|
const INITIAL_STATE: State = {
|
|
installedPlugins: new Map(),
|
|
};
|
|
|
|
export default function reducer(
|
|
state: State = INITIAL_STATE,
|
|
action: Actions,
|
|
): State {
|
|
if (action.type === 'REGISTER_INSTALLED_PLUGINS') {
|
|
return {
|
|
...state,
|
|
installedPlugins: action.payload,
|
|
};
|
|
} else {
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export const registerInstalledPlugins = (payload: PluginMap): Action => ({
|
|
type: 'REGISTER_INSTALLED_PLUGINS',
|
|
payload,
|
|
});
|