From 6a35078244296c5ecae8df256b82adb9557ce4a2 Mon Sep 17 00:00:00 2001 From: cooolbros Date: Wed, 27 Nov 2024 15:00:16 +1100 Subject: [PATCH] Only emit when Uri changes --- .../src/VirtualFileSystem/VirtualFileSystem.ts | 7 ++++--- .../mounts/TeamFortress2FileSystem.ts | 7 ++++--- .../VirtualFileSystem/mounts/WildcardFileSystem.ts | 5 +++-- packages/common/src/Uri.ts | 12 ++++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/client/src/VirtualFileSystem/VirtualFileSystem.ts b/packages/client/src/VirtualFileSystem/VirtualFileSystem.ts index 0f6bb48..24d0470 100644 --- a/packages/client/src/VirtualFileSystem/VirtualFileSystem.ts +++ b/packages/client/src/VirtualFileSystem/VirtualFileSystem.ts @@ -1,5 +1,5 @@ -import type { Uri } from "common/Uri" -import { combineLatest, map, Observable } from "rxjs" +import { Uri } from "common/Uri" +import { combineLatest, distinctUntilChanged, map, Observable } from "rxjs" import type { FileSystemMountPoint } from "./FileSystemMountPoint" /** @@ -12,7 +12,8 @@ export function VirtualFileSystem(fileSystems: FileSystemMountPoint[]): FileSyst let observable = observables.get(path) if (!observable) { observable = combineLatest(fileSystems.map((fileSystem) => fileSystem.resolveFile(path))).pipe( - map((uris) => uris.find((uri) => uri != null) ?? null) + map((uris) => uris.find((uri) => uri != null) ?? null), + distinctUntilChanged(Uri.equals) ) observables.set(path, observable) } diff --git a/packages/client/src/VirtualFileSystem/mounts/TeamFortress2FileSystem.ts b/packages/client/src/VirtualFileSystem/mounts/TeamFortress2FileSystem.ts index 533c499..e7d0af1 100644 --- a/packages/client/src/VirtualFileSystem/mounts/TeamFortress2FileSystem.ts +++ b/packages/client/src/VirtualFileSystem/mounts/TeamFortress2FileSystem.ts @@ -1,5 +1,5 @@ -import type { Uri } from "common/Uri" -import { combineLatest, map, Observable } from "rxjs" +import { Uri } from "common/Uri" +import { combineLatest, distinctUntilChanged, map, Observable } from "rxjs" import { VDF } from "vdf" import * as vscode from "vscode" import { z } from "zod" @@ -84,7 +84,8 @@ export async function TeamFortress2FileSystem(teamFortress2Folder: Uri, factory: let observable = observables.get(path) if (!observable) { observable = combineLatest(fileSystems.map((fileSystem) => fileSystem.resolveFile(path))).pipe( - map((uris) => uris.find((uri) => uri != null) ?? null) + map((uris) => uris.find((uri) => uri != null) ?? null), + distinctUntilChanged(Uri.equals) ) observables.set(path, observable) } diff --git a/packages/client/src/VirtualFileSystem/mounts/WildcardFileSystem.ts b/packages/client/src/VirtualFileSystem/mounts/WildcardFileSystem.ts index a0bed9b..798738e 100644 --- a/packages/client/src/VirtualFileSystem/mounts/WildcardFileSystem.ts +++ b/packages/client/src/VirtualFileSystem/mounts/WildcardFileSystem.ts @@ -1,5 +1,5 @@ import { Uri } from "common/Uri" -import { BehaviorSubject, map, Observable, Subscription } from "rxjs" +import { BehaviorSubject, distinctUntilChanged, map, Observable, Subscription } from "rxjs" import * as vscode from "vscode" import type { FileSystemMountPoint } from "../FileSystemMountPoint" import type { FileSystemMountPointFactory } from "../FileSystemMountPointFactory" @@ -144,7 +144,8 @@ export async function WildcardFileSystem(uri: Uri, factory: FileSystemMountPoint }) }, map((uris) => uris.map(({ value }) => value)), - map((uris) => uris.find((uri) => uri != null) ?? null) + map((uris) => uris.find((uri) => uri != null) ?? null), + distinctUntilChanged(Uri.equals) ) observables.set(path, observable) } diff --git a/packages/common/src/Uri.ts b/packages/common/src/Uri.ts index 1c3d7fd..61b8d12 100644 --- a/packages/common/src/Uri.ts +++ b/packages/common/src/Uri.ts @@ -12,6 +12,18 @@ export class Uri { fragment: z.string(), }).transform((arg) => new Uri(arg)) + public static equals(a: Uri | null, b: Uri | null): boolean { + if (a == b) { + return true + } + + if (a != null && b != null) { + return a.equals(b) + } + + return false + } + private readonly uri: URI public readonly scheme: string