From 073ac2469767bb246c38c81328765d710b36de99 Mon Sep 17 00:00:00 2001 From: Aaron Silverman Date: Thu, 30 May 2024 21:01:40 -0600 Subject: [PATCH] Remove old MemoryStore entries when setting new entries (#69) * test case * remove old entries * feedback from PR --- .gitignore | 3 ++- package.json | 4 ++-- src/configuration-store/memory.store.spec.ts | 12 +++++++++--- src/configuration-store/memory.store.ts | 4 +--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a7a205fb..9292a667 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,6 @@ yarn-error.log test/data .vscode/settings.json +.idea -.DS_Store \ No newline at end of file +.DS_Store diff --git a/package.json b/package.json index 5f10e276..65404865 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eppo/js-client-sdk-common", - "version": "3.0.8", + "version": "3.0.9", "description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)", "main": "dist/index.js", "files": [ @@ -68,4 +68,4 @@ "semver": "^7.5.4", "universal-base64": "^2.1.0" } -} \ No newline at end of file +} diff --git a/src/configuration-store/memory.store.spec.ts b/src/configuration-store/memory.store.spec.ts index f88b1b08..fae8c65e 100644 --- a/src/configuration-store/memory.store.spec.ts +++ b/src/configuration-store/memory.store.spec.ts @@ -37,8 +37,14 @@ describe('MemoryOnlyConfigurationStore', () => { }); it('should overwrite existing entries', async () => { - await memoryStore.setEntries({ key1: 'value1' }); - await memoryStore.setEntries({ key1: 'newValue1' }); - expect(memoryStore.get('key1')).toBe('newValue1'); + await memoryStore.setEntries({ toBeReplaced: 'old value', toBeRemoved: 'delete me' }); + expect(memoryStore.get('toBeReplaced')).toBe('old value'); + expect(memoryStore.get('toBeRemoved')).toBe('delete me'); + expect(memoryStore.get('toBeAdded')).toBeNull(); + + await memoryStore.setEntries({ toBeReplaced: 'new value', toBeAdded: 'add me' }); + expect(memoryStore.get('toBeReplaced')).toBe('new value'); + expect(memoryStore.get('toBeRemoved')).toBeNull(); + expect(memoryStore.get('toBeAdded')).toBe('add me'); }); }); diff --git a/src/configuration-store/memory.store.ts b/src/configuration-store/memory.store.ts index 3bc24023..f1023599 100644 --- a/src/configuration-store/memory.store.ts +++ b/src/configuration-store/memory.store.ts @@ -17,9 +17,7 @@ export class MemoryStore implements ISyncStore { } setEntries(entries: Record): void { - Object.entries(entries).forEach(([key, val]) => { - this.store[key] = val; - }); + this.store = { ...entries }; this.initialized = true; } }