From 25da9ebf5eca9ecad7e03cae69b2513ec5ea95f5 Mon Sep 17 00:00:00 2001 From: ByteAtATime Date: Thu, 27 Nov 2025 21:33:43 -0800 Subject: [PATCH] fix: use arrow functions in Cache to maintain `this` context --- renderer/src/api/cache.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/renderer/src/api/cache.ts b/renderer/src/api/cache.ts index 6498169..73f3112 100644 --- a/renderer/src/api/cache.ts +++ b/renderer/src/api/cache.ts @@ -25,25 +25,25 @@ export class Cache { return path.join(this.directory, hash); } - public get(key: string): string | undefined { + public get = (key: string): string | undefined => { const filePath = this.getPath(key); if (fs.existsSync(filePath)) { return fs.readFileSync(filePath, "utf-8"); } return undefined; - } + }; - public has(key: string): boolean { + public has = (key: string): boolean => { return fs.existsSync(this.getPath(key)); - } + }; - public set(key: string, data: string): void { + public set = (key: string, data: string): void => { const filePath = this.getPath(key); fs.writeFileSync(filePath, data); this.notifySubscribers(key, data); - } + }; - public remove(key: string): boolean { + public remove = (key: string): boolean => { const filePath = this.getPath(key); if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); @@ -51,11 +51,11 @@ export class Cache { return true; } return false; - } + }; - public clear( + public clear = ( options: { notifySubscribers: boolean } = { notifySubscribers: true } - ): void { + ): void => { if (fs.existsSync(this.directory)) { const files = fs.readdirSync(this.directory); for (const file of files) { @@ -65,24 +65,24 @@ export class Cache { if (options.notifySubscribers) { this.notifySubscribers(undefined, undefined); } - } + }; - public isEmpty(): boolean { + public isEmpty = (): boolean => { if (!fs.existsSync(this.directory)) { return true; } const files = fs.readdirSync(this.directory); return files.length === 0; - } + }; - public subscribe( + public subscribe = ( subscriber: RaycastApiType.Cache.Subscriber - ): RaycastApiType.Cache.Subscription { + ): RaycastApiType.Cache.Subscription => { this.subscribers.add(subscriber); return () => { this.subscribers.delete(subscriber); }; - } + }; private notifySubscribers(key: string | undefined, data: string | undefined) { for (const subscriber of this.subscribers) {