Skip to content

Commit

Permalink
Remove old MemoryStore entries when setting new entries (#69)
Browse files Browse the repository at this point in the history
* test case

* remove old entries

* feedback from PR
  • Loading branch information
aarsilv authored May 31, 2024
1 parent 1c75a3f commit 073ac24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ yarn-error.log

test/data
.vscode/settings.json
.idea

.DS_Store
.DS_Store
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -68,4 +68,4 @@
"semver": "^7.5.4",
"universal-base64": "^2.1.0"
}
}
}
12 changes: 9 additions & 3 deletions src/configuration-store/memory.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 1 addition & 3 deletions src/configuration-store/memory.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class MemoryStore<T> implements ISyncStore<T> {
}

setEntries(entries: Record<string, T>): void {
Object.entries(entries).forEach(([key, val]) => {
this.store[key] = val;
});
this.store = { ...entries };
this.initialized = true;
}
}
Expand Down

0 comments on commit 073ac24

Please sign in to comment.