Command processing (2/n): testing
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 Flipper mocking helpers to allow testing of plugin commands, and wrote some tests for pluginManager. Reviewed By: mweststrate Differential Revision: D26450344 fbshipit-source-id: 0e8414517cc1ad353781dffd7ffb4a5f9a815d38
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8efdde08c4
commit
24aed8fd45
@@ -35,15 +35,29 @@ function refreshInstalledPlugins(store: Store) {
|
||||
.then((plugins) => store.dispatch(registerInstalledPlugins(plugins)));
|
||||
}
|
||||
|
||||
export default (store: Store, _logger: Logger) => {
|
||||
export default (
|
||||
store: Store,
|
||||
_logger: Logger,
|
||||
{runSideEffectsSynchronously}: {runSideEffectsSynchronously: boolean} = {
|
||||
runSideEffectsSynchronously: false,
|
||||
},
|
||||
) => {
|
||||
// This needn't happen immediately and is (light) I/O work.
|
||||
window.requestIdleCallback(() => {
|
||||
refreshInstalledPlugins(store);
|
||||
});
|
||||
if (window.requestIdleCallback) {
|
||||
window.requestIdleCallback(() => {
|
||||
refreshInstalledPlugins(store);
|
||||
});
|
||||
}
|
||||
|
||||
sideEffect(
|
||||
const unsubscribeHandlePluginCommands = sideEffect(
|
||||
store,
|
||||
{name: 'handlePluginActivation', throttleMs: 1000, fireImmediately: true},
|
||||
{
|
||||
name: 'handlePluginCommands',
|
||||
throttleMs: 0,
|
||||
fireImmediately: true,
|
||||
runSynchronously: runSideEffectsSynchronously, // Used to simplify writing tests, if "true" passed, the all side effects will be called synchronously and immediately after changes
|
||||
noTimeBudgetWarns: true, // These side effects are critical, so we're doing them with zero throttling and want to avoid unnecessary warns
|
||||
},
|
||||
(state) => state.pluginManager.pluginCommandsQueue,
|
||||
(queue, store) => {
|
||||
for (const command of queue) {
|
||||
@@ -59,6 +73,9 @@ export default (store: Store, _logger: Logger) => {
|
||||
store.dispatch(pluginCommandsProcessed(queue.length));
|
||||
},
|
||||
);
|
||||
return async () => {
|
||||
unsubscribeHandlePluginCommands();
|
||||
};
|
||||
};
|
||||
|
||||
function loadPlugin(store: Store, payload: LoadPluginActionPayload) {
|
||||
|
||||
Reference in New Issue
Block a user