mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
don't allow optional args in actions
This can lead to subtle bugs. Fixes firmware flash button not working.
This commit is contained in:
@@ -225,7 +225,7 @@ const mapDispatchToProps: DispatchProps = {
|
||||
onProgramStorageChanged: storageChanged,
|
||||
// REVISIT: the options here might need to be changed - hopefully there is
|
||||
// one setting that works for all hub types for cases where we aren't connected.
|
||||
onCheck: compile,
|
||||
onCheck: (script) => compile(script, []),
|
||||
onToggleDocs: () => toggleBoolean(SettingId.ShowDocs),
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ const mapDispatchToProps: DispatchProps = {
|
||||
onFile: flashFirmware,
|
||||
onReject: (file) =>
|
||||
notification.add('error', `'${file.name}' is not a valid firmware file.`),
|
||||
onClick: () => flashFirmware(),
|
||||
onClick: () => flashFirmware(null),
|
||||
};
|
||||
|
||||
const mergeProps = (
|
||||
|
||||
@@ -129,15 +129,15 @@ export type FailToFinishReason =
|
||||
* Action that flashes firmware to a hub.
|
||||
*/
|
||||
export type FlashFirmwareFlashAction = Action<FlashFirmwareActionType.FlashFirmware> & {
|
||||
/** The firmware zip file data or undefined to get firmware later. */
|
||||
data?: ArrayBuffer;
|
||||
/** The firmware zip file data or `null` to get firmware later. */
|
||||
data: ArrayBuffer | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new action to flash firmware to a hub.
|
||||
* @param data The firmware zip file data or undefined to get firmware later.
|
||||
* @param data The firmware zip file data or `null` to get firmware later.
|
||||
*/
|
||||
export function flashFirmware(data?: ArrayBuffer): FlashFirmwareFlashAction {
|
||||
export function flashFirmware(data: ArrayBuffer | null): FlashFirmwareFlashAction {
|
||||
return { type: FlashFirmwareActionType.FlashFirmware, data };
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -88,7 +88,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -296,7 +296,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -370,7 +370,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -440,7 +440,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -513,7 +513,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -579,7 +579,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -651,7 +651,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -739,7 +739,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -811,7 +811,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -912,7 +912,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -1022,7 +1022,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -1172,7 +1172,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
@@ -1854,7 +1854,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
saga.put(flashFirmwareAction(null));
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator {
|
||||
program = editor.getValue();
|
||||
}
|
||||
|
||||
if (action.data !== undefined) {
|
||||
if (action.data !== null) {
|
||||
({ firmware, deviceId } = yield* loadFirmware(action.data, program));
|
||||
}
|
||||
|
||||
|
||||
@@ -124,13 +124,13 @@ export function didFailToConnect(
|
||||
|
||||
export function didFailToConnect(
|
||||
reason: BootloaderConnectionFailureReason,
|
||||
err?: Error,
|
||||
arg1?: Error,
|
||||
): BootloaderConnectionDidFailToConnectAction {
|
||||
if (reason === BootloaderConnectionFailureReason.Unknown) {
|
||||
return <BootloaderConnectionDidFailToConnectAction>{
|
||||
type: BootloaderConnectionActionType.DidFailToConnect,
|
||||
reason,
|
||||
err,
|
||||
err: arg1,
|
||||
};
|
||||
}
|
||||
return { type: BootloaderConnectionActionType.DidFailToConnect, reason };
|
||||
|
||||
+2
-2
@@ -14,10 +14,10 @@ export type MpyCompileAction = Action<MpyActionType.Compile> & {
|
||||
/** The script to compile. */
|
||||
readonly script: string;
|
||||
/** The compiler command line options */
|
||||
options?: string[];
|
||||
options: string[];
|
||||
};
|
||||
|
||||
export function compile(script: string, options?: string[]): MpyCompileAction {
|
||||
export function compile(script: string, options: string[]): MpyCompileAction {
|
||||
return { type: MpyActionType.Compile, script, options };
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ enum MpyFeatureFlags {
|
||||
test('compiler works', async () => {
|
||||
const saga = new AsyncSaga(mpy);
|
||||
|
||||
saga.put(compile('print("hello!")'));
|
||||
saga.put(compile('print("hello!")', []));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(MpyActionType.DidCompile);
|
||||
@@ -32,7 +32,7 @@ test('compiler works', async () => {
|
||||
test('compiler error works', async () => {
|
||||
const saga = new AsyncSaga(mpy);
|
||||
|
||||
saga.put(compile('syntax error!'));
|
||||
saga.put(compile('syntax error!', []));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(MpyActionType.DidFailToCompile);
|
||||
|
||||
Reference in New Issue
Block a user