Fix duplicate list_remote_branches call

- give head and fetches streams an initial value
This commit is contained in:
Mattias Granlund 2024-01-05 12:06:15 +01:00
parent 0fcf6877f7
commit 55ae30f62f
4 changed files with 14 additions and 13 deletions

View File

@ -1,6 +1,9 @@
import { subscribeToFetches } from '$lib/backend/fetches';
import { Observable } from 'rxjs';
import { Observable, shareReplay, startWith } from 'rxjs';
export function getFetchNotifications(projectId: string): Observable<void> {
return new Observable((observer) => subscribeToFetches(projectId, () => observer.next()));
export function getFetchNotifications(projectId: string): Observable<unknown> {
return new Observable((observer) => subscribeToFetches(projectId, () => observer.next())).pipe(
startWith(undefined),
shareReplay(1)
);
}

View File

@ -1,10 +1,10 @@
import { getHead, subscribeToHead } from '$lib/backend/heads';
import { Observable, concat, from } from 'rxjs';
import { Observable, concat, from, shareReplay } from 'rxjs';
export function getHeads(projectId: string): Observable<string> {
const head$ = from(getHead(projectId));
const stream$ = new Observable<string>((subscriber) =>
subscribeToHead(projectId, (head) => subscriber.next(head))
);
return concat(head$, stream$);
return concat(head$, stream$).pipe(shareReplay(1));
}

View File

@ -5,9 +5,8 @@ import {
BehaviorSubject,
Observable,
catchError,
combineLatestWith,
combineLatest,
map,
merge,
of,
shareReplay,
switchMap
@ -24,8 +23,7 @@ export class RemoteBranchService {
head$: Observable<any>,
baseBranch$: Observable<any>
) {
this.branches$ = merge(fetches$, head$, baseBranch$).pipe(
combineLatestWith(this.reload$),
this.branches$ = combineLatest([baseBranch$, this.reload$, head$, fetches$]).pipe(
switchMap(() => getRemoteBranchesData({ projectId })),
map((branches) => branches.filter((b) => b.ahead != 0)),
shareReplay(1),

View File

@ -2,7 +2,6 @@ import { BaseBranch, Branch } from './types';
import { plainToInstance } from 'class-transformer';
import { UserError, invoke, listen } from '$lib/backend/ipc';
import {
merge,
switchMap,
Observable,
shareReplay,
@ -14,7 +13,8 @@ import {
tap,
map,
firstValueFrom,
timeout
timeout,
combineLatest
} from 'rxjs';
export class VirtualBranchService {
@ -83,8 +83,8 @@ export class BaseBranchService {
error$ = new BehaviorSubject<any>(undefined);
private reload$ = new BehaviorSubject<void>(undefined);
constructor(projectId: string, fetches$: Observable<void>, head$: Observable<string>) {
this.base$ = merge(fetches$, head$, this.reload$).pipe(
constructor(projectId: string, fetches$: Observable<unknown>, head$: Observable<string>) {
this.base$ = combineLatest([fetches$, head$, this.reload$]).pipe(
debounceTime(100),
switchMap(() => getBaseBranch({ projectId })),
catchError((e) => {