Add error logger service

This commit is contained in:
David Lechner
2020-05-26 21:20:08 -05:00
committed by David Lechner
parent 6e4b22f841
commit ec05ad38aa
2 changed files with 18 additions and 1 deletions
+16
View File
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { Action } from '../actions';
import { BootloaderConnectionActionType } from '../actions/bootloader';
import { combineServices } from '.';
async function consoleLog(action: Action): Promise<void> {
switch (action.type) {
case BootloaderConnectionActionType.DidError:
console.error(action.err);
break;
}
}
export default combineServices(consoleLog);
+2 -1
View File
@@ -6,6 +6,7 @@ import { Action, Dispatch } from '../actions';
import { RootState } from '../reducers';
import bootloader from './bootloader';
import editor from './editor';
import errorLog from './error-log';
type Service = (action: Action, dispatch: Dispatch, state: RootState) => Promise<void>;
@@ -27,7 +28,7 @@ export function combineServices(...services: Service[]): Service {
};
}
const rootService = combineServices(bootloader, editor);
const rootService = combineServices(bootloader, editor, errorLog);
const serviceMiddleware: Middleware = (store) => (next) => (action): unknown => {
runService(rootService, action, store.dispatch, store.getState());