Update existing subscriptions to use sideEffect

Summary: See previous two diffs, this applies the abstraction to our code base

Reviewed By: passy

Differential Revision: D20679687

fbshipit-source-id: 05e340dca3f832971783a844a78d1ffd553ff9d2
This commit is contained in:
Michel Weststrate
2020-03-27 04:39:06 -07:00
committed by Facebook GitHub Bot
parent 7a40d3f0a3
commit 8fa4b5ccb2
4 changed files with 142 additions and 136 deletions

View File

@@ -29,6 +29,7 @@ import path from 'path';
import {default as config} from '../utils/processConfig';
import isProduction from '../utils/isProduction';
import {notNull} from '../utils/typeUtils';
import {sideEffect} from '../utils/sideEffect';
export type PluginDefinition = {
id?: string;
@@ -63,20 +64,17 @@ export default (store: Store, _logger: Logger) => {
store.dispatch(addFailedPlugins(failedPlugins));
store.dispatch(registerPlugins(initialPlugins));
let state: State | null = null;
store.subscribe(() => {
const newState = store.getState().plugins;
if (state !== newState) {
sideEffect(
store,
{name: 'setupMenuBar', throttleMs: 100},
(state) => state.plugins,
(plugins, store) => {
setupMenuBar(
[
...newState.devicePlugins.values(),
...newState.clientPlugins.values(),
],
[...plugins.devicePlugins.values(), ...plugins.clientPlugins.values()],
store,
);
}
state = newState;
});
},
);
};
function getBundledPlugins(): Array<PluginDefinition> {