From 5bd92c841206db92bc27d33ce55ada76b65809ea Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 23 Feb 2025 09:59:57 +0000 Subject: [PATCH] Remove global files & store data as field --- frontend/test-client/src/agent/mock-client.ts | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/frontend/test-client/src/agent/mock-client.ts b/frontend/test-client/src/agent/mock-client.ts index 0ce689c4..6fc8f15b 100644 --- a/frontend/test-client/src/agent/mock-client.ts +++ b/frontend/test-client/src/agent/mock-client.ts @@ -9,18 +9,16 @@ import { assert } from "../utils/assert"; export class MockClient implements FileSystemOperations { protected readonly localFiles: Record = {}; protected client!: SyncClient; + protected data: unknown = ""; public constructor( - protected readonly globalFiles: Record, private readonly initialSettings: Partial ) {} public async init(): Promise { - let _data: unknown = ""; - this.client = await SyncClient.create(this, { - load: async () => _data, - save: async (data: unknown) => void (_data = data) + load: async () => this.data, + save: async (data: unknown) => void (this.data = data) }); await Promise.all( @@ -74,9 +72,8 @@ export class MockClient implements FileSystemOperations { if (path in this.localFiles) { throw new Error(`File ${path} already exists`); } - this.globalFiles[path] = newContent; this.localFiles[path] = newContent; - this.client.syncer.syncLocallyCreatedFile(path, new Date()); + void this.client.syncer.syncLocallyCreatedFile(path, new Date()); } public async createDirectory(path: RelativePath): Promise { @@ -93,7 +90,6 @@ export class MockClient implements FileSystemOperations { const currentContent = new TextDecoder().decode(this.localFiles[path]); const newContent = updater(currentContent); const newContentUint8Array = new TextEncoder().encode(newContent); - this.globalFiles[path] = newContentUint8Array; this.localFiles[path] = newContentUint8Array; void this.client.syncer.syncLocallyUpdatedFile({ @@ -105,7 +101,6 @@ export class MockClient implements FileSystemOperations { } public async write(path: RelativePath, content: Uint8Array): Promise { - this.globalFiles[path] = content; this.localFiles[path] = content; void this.client.syncer.syncLocallyUpdatedFile({ @@ -116,10 +111,6 @@ export class MockClient implements FileSystemOperations { public async delete(path: RelativePath): Promise { delete this.localFiles[path]; - if (path in this.globalFiles) { - delete this.globalFiles[path]; - } - void this.client.syncer.syncLocallyDeletedFile(path); } @@ -132,11 +123,8 @@ export class MockClient implements FileSystemOperations { } this.localFiles[newPath] = this.localFiles[oldPath]; - delete this.localFiles[oldPath]; - - if (oldPath in this.globalFiles) { - this.globalFiles[newPath] = this.localFiles[oldPath]; - delete this.globalFiles[oldPath]; + if (oldPath !== newPath) { + delete this.localFiles[oldPath]; } void this.client.syncer.syncLocallyUpdatedFile({