Skip to content

Commit

Permalink
Only emit when Uri changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Nov 27, 2024
1 parent 29bed4b commit 6a35078
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/client/src/VirtualFileSystem/VirtualFileSystem.ts
Original file line number Diff line number Diff line change
@@ -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"

/**
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions packages/common/src/Uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a35078

Please sign in to comment.