From 9ac878ad21cb90763e9652a539c770048c1d92a2 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 18 Mar 2026 11:20:48 +0100 Subject: [PATCH] better typescript --- src/state/AndroidControlledAudioOutput.ts | 55 ++++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/state/AndroidControlledAudioOutput.ts b/src/state/AndroidControlledAudioOutput.ts index 8c223685..ce4974ff 100644 --- a/src/state/AndroidControlledAudioOutput.ts +++ b/src/state/AndroidControlledAudioOutput.ts @@ -153,7 +153,7 @@ export class AndroidControlledAudioOutput implements MediaDevice< // Merge the two possible inputs observable as a single // stream of actions that will update the state of the controller. - const actions$ = merge( + const actions$: Observable = merge( this.controlledDevices$.pipe( map( (devices) => @@ -177,34 +177,35 @@ export class AndroidControlledAudioOutput implements MediaDevice< actions$.pipe( startWith(initialAction), scan((state, action): ControllerState => { - if (action.type === "deviceUpdated") { - const chosenDevice = this.chooseEffectiveSelection({ - previousDevices: state.devices, - availableDevices: action.devices, - currentSelectedId: state.selectedDeviceId, - preferredDeviceId: state.preferredDeviceId, - }); + switch (action.type) { + case "deviceUpdated": { + const chosenDevice = this.chooseEffectiveSelection({ + previousDevices: state.devices, + availableDevices: action.devices, + currentSelectedId: state.selectedDeviceId, + preferredDeviceId: state.preferredDeviceId, + }); - return { - ...state, - devices: action.devices, - selectedDeviceId: chosenDevice, - }; - } else if (action.type === "selectDevice") { - const chosenDevice = this.chooseEffectiveSelection({ - previousDevices: state.devices, - availableDevices: state.devices, - currentSelectedId: state.selectedDeviceId, - preferredDeviceId: action.deviceId, - }); + return { + ...state, + devices: action.devices, + selectedDeviceId: chosenDevice, + }; + } + case "selectDevice": { + const chosenDevice = this.chooseEffectiveSelection({ + previousDevices: state.devices, + availableDevices: state.devices, + currentSelectedId: state.selectedDeviceId, + preferredDeviceId: action.deviceId, + }); - return { - ...state, - preferredDeviceId: action.deviceId, - selectedDeviceId: chosenDevice, - }; - } else { - return state; + return { + ...state, + preferredDeviceId: action.deviceId, + selectedDeviceId: chosenDevice, + }; + } } }, initialState), ),