From c34516e871e304d6fa30629f9061378aaa6b760c Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 12 Jul 2025 00:28:24 -0400 Subject: [PATCH] Use the initialValue parameter of 'behavior' instead of startWith --- src/state/CallViewModel.ts | 6 ++---- src/state/MediaDevices.ts | 8 +++----- src/utils/test.ts | 11 +++++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index 021f8f77..e9b86d99 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -403,7 +403,7 @@ export class CallViewModel extends ViewModel { */ private readonly rawRemoteParticipants$ = this.scope.behavior< RemoteParticipant[] - >(connectedParticipantsObserver(this.livekitRoom).pipe(startWith([]))); + >(connectedParticipantsObserver(this.livekitRoom), []); /** * Lists of RemoteParticipants to "hold" on display, even if LiveKit claims that @@ -889,9 +889,7 @@ export class CallViewModel extends ViewModel { distinctUntilChanged(), ); - private readonly pipEnabled$: Observable = setPipEnabled$.pipe( - startWith(false), - ); + private readonly pipEnabled$ = this.scope.behavior(setPipEnabled$, false); private readonly naturalWindowMode$ = this.scope.behavior( fromEvent(window, "resize").pipe( diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index a3a2dc1e..ef60dd24 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -122,8 +122,8 @@ function availableRawDevices$( ) : devices$, ), - startWith([]), ), + [], ); } @@ -373,10 +373,8 @@ export class MediaDevices { // API. This flag never resets to false, because once permissions are granted // the first time, the user won't be prompted again until reload of the page. private readonly usingNames$ = this.scope.behavior( - this.deviceNamesRequest$.pipe( - map(() => true), - startWith(false), - ), + this.deviceNamesRequest$.pipe(map(() => true)), + false, ); public readonly audioInput: MediaDevice< DeviceLabel, diff --git a/src/utils/test.ts b/src/utils/test.ts index 01cadd85..cad2b521 100644 --- a/src/utils/test.ts +++ b/src/utils/test.ts @@ -4,7 +4,7 @@ Copyright 2023, 2024 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE in the repository root for full details. */ -import { map, type Observable, of, type SchedulerLike, startWith } from "rxjs"; +import { map, type Observable, of, type SchedulerLike } from "rxjs"; import { type RunHelpers, TestScheduler } from "rxjs/testing"; import { expect, vi, vitest } from "vitest"; import { @@ -125,9 +125,12 @@ export function withTestScheduler( values === undefined ? (initialMarble as T) : values[initialMarble]; // The remainder of the marble diagram should start on frame 1 return scope.behavior( - helpers - .hot(`-${marbles.slice(initialMarbleIndex + 1)}`, values, error) - .pipe(startWith(initialValue)), + helpers.hot( + `-${marbles.slice(initialMarbleIndex + 1)}`, + values, + error, + ), + initialValue, ); }, }),