rename app startup action using do/did pattern

This commit is contained in:
David Lechner
2021-01-18 17:29:03 -06:00
parent 54439a4cbc
commit f72c6ad5de
6 changed files with 23 additions and 23 deletions
+5 -5
View File
@@ -8,7 +8,7 @@ import { Action } from 'redux';
/** App action types. */
export enum AppActionType {
/** The app has just ben started. */
Startup = 'app.action.startup',
DidStart = 'app.action.didStart',
/** Open settings dialog. */
OpenSettings = 'app.action.openSettings',
/** Close settings dialog. */
@@ -24,11 +24,11 @@ export enum AppActionType {
}
/** Action that indicates the app has just started. */
export type AppStartupAction = Action<AppActionType.Startup>;
export type AppDidStartAction = Action<AppActionType.DidStart>;
/** Creates an action that indicates the app has just started. */
export function startup(): AppStartupAction {
return { type: AppActionType.Startup };
export function didStart(): AppDidStartAction {
return { type: AppActionType.DidStart };
}
/** Action to open the settings dialog. */
@@ -81,7 +81,7 @@ export function closeLicenseDialog(): AppCloseLicenseDialogAction {
/** common type for all app actions. */
export type AppAction =
| AppStartupAction
| AppDidStartAction
| AppOpenSettingsAction
| AppCloseSettingsAction
| AppOpenAboutDialogAction
+2 -2
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import { all, put } from 'redux-saga/effects';
import { startup } from '../actions/app';
import { didStart } from '../actions/app';
import bleUart from './ble-uart';
import editor from './editor';
import errorLog from './error-log';
@@ -31,6 +31,6 @@ export default function* (): Generator {
notification(),
settings(),
terminal(),
put(startup()),
put(didStart()),
]);
}
+10 -10
View File
@@ -4,7 +4,7 @@
// Tests for settings sagas.
import { AsyncSaga } from '../../test';
import { startup } from '../actions/app';
import { didStart } from '../actions/app';
import { didBooleanChange, didFailToSetBoolean, setBoolean } from '../actions/settings';
import { SettingsState } from '../reducers/settings';
import { SettingId } from '../settings/user';
@@ -25,7 +25,7 @@ describe('startup', () => {
).mockReturnValue(null);
innerWidth = 1024;
saga.put(startup());
saga.put(didStart());
// does nothing
@@ -41,7 +41,7 @@ describe('startup', () => {
).mockReturnValue(null);
innerWidth = 800;
saga.put(startup());
saga.put(didStart());
// does nothing
@@ -64,7 +64,7 @@ describe('startup', () => {
});
innerWidth = 1024;
saga.put(startup());
saga.put(didStart());
// does nothing
@@ -87,7 +87,7 @@ describe('startup', () => {
});
innerWidth = 800;
saga.put(startup());
saga.put(didStart());
// requests documentation to be shown
const action = await saga.take();
@@ -112,7 +112,7 @@ describe('startup', () => {
});
innerWidth = 1024;
saga.put(startup());
saga.put(didStart());
// requests documentation to be hidden
const action = await saga.take();
@@ -137,7 +137,7 @@ describe('startup', () => {
});
innerWidth = 800;
saga.put(startup());
saga.put(didStart());
// does nothing
@@ -154,7 +154,7 @@ describe('startup', () => {
'getItem',
).mockReturnValue(null);
saga.put(startup());
saga.put(didStart());
// does nothing
@@ -176,7 +176,7 @@ describe('startup', () => {
}
});
saga.put(startup());
saga.put(didStart());
// requests to enable dark mode
const action = await saga.take();
@@ -200,7 +200,7 @@ describe('startup', () => {
}
});
saga.put(startup());
saga.put(didStart());
// does nothing
+1 -1
View File
@@ -101,6 +101,6 @@ function* storeSetting(action: SettingsSetBooleanAction): Generator {
export default function* (): Generator {
yield fork(monitorLocalStorage);
yield takeEvery(AppActionType.Startup, loadSettings);
yield takeEvery(AppActionType.DidStart, loadSettings);
yield takeEvery(SettingsActionType.SetBoolean, storeSetting);
}
+2 -2
View File
@@ -3,7 +3,7 @@
import { AsyncSaga, delay } from '../../test';
import { startup } from '../actions/app';
import { didStart } from '../actions/app';
import {
BleUartActionType,
BleUartWriteAction,
@@ -295,7 +295,7 @@ describe('Data receiver filters out hub status', () => {
test('Terminal data source responds to send data actions', async () => {
const saga = new AsyncSaga(terminal);
saga.put(startup());
saga.put(didStart());
const dataSourceAction = await saga.take();
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
+3 -3
View File
@@ -14,7 +14,7 @@ import {
} from 'redux-saga/effects';
import PushStream from 'zen-push';
import { Action } from '../actions';
import { AppActionType, AppStartupAction } from '../actions/app';
import { AppActionType, AppDidStartAction } from '../actions/app';
import {
BleUartActionType,
BleUartNotifyAction,
@@ -36,7 +36,7 @@ const encoder = new TextEncoder();
const decoder = new TextDecoder();
const terminalDataSource = new PushStream<string>();
function* startup(_action: AppStartupAction): Generator {
function* startup(_action: AppDidStartAction): Generator {
yield put(setDataSource(terminalDataSource.observable));
}
@@ -146,7 +146,7 @@ function sendTerminalData(action: TerminalDataReceiveDataAction): void {
}
export default function* (): Generator {
yield takeEvery(AppActionType.Startup, startup);
yield takeEvery(AppActionType.DidStart, startup);
yield takeEvery(BleUartActionType.Notify, receiveUartData);
yield fork(receiveTerminalData);
yield takeEvery(TerminalActionType.SendData, sendTerminalData);