Skip to content

Commit 073ac24

Browse files
authored
Remove old MemoryStore entries when setting new entries (#69)
* test case * remove old entries * feedback from PR
1 parent 1c75a3f commit 073ac24

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ yarn-error.log
1010

1111
test/data
1212
.vscode/settings.json
13+
.idea
1314

14-
.DS_Store
15+
.DS_Store

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "3.0.8",
3+
"version": "3.0.9",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [
@@ -68,4 +68,4 @@
6868
"semver": "^7.5.4",
6969
"universal-base64": "^2.1.0"
7070
}
71-
}
71+
}

src/configuration-store/memory.store.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ describe('MemoryOnlyConfigurationStore', () => {
3737
});
3838

3939
it('should overwrite existing entries', async () => {
40-
await memoryStore.setEntries({ key1: 'value1' });
41-
await memoryStore.setEntries({ key1: 'newValue1' });
42-
expect(memoryStore.get('key1')).toBe('newValue1');
40+
await memoryStore.setEntries({ toBeReplaced: 'old value', toBeRemoved: 'delete me' });
41+
expect(memoryStore.get('toBeReplaced')).toBe('old value');
42+
expect(memoryStore.get('toBeRemoved')).toBe('delete me');
43+
expect(memoryStore.get('toBeAdded')).toBeNull();
44+
45+
await memoryStore.setEntries({ toBeReplaced: 'new value', toBeAdded: 'add me' });
46+
expect(memoryStore.get('toBeReplaced')).toBe('new value');
47+
expect(memoryStore.get('toBeRemoved')).toBeNull();
48+
expect(memoryStore.get('toBeAdded')).toBe('add me');
4349
});
4450
});

src/configuration-store/memory.store.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export class MemoryStore<T> implements ISyncStore<T> {
1717
}
1818

1919
setEntries(entries: Record<string, T>): void {
20-
Object.entries(entries).forEach(([key, val]) => {
21-
this.store[key] = val;
22-
});
20+
this.store = { ...entries };
2321
this.initialized = true;
2422
}
2523
}

0 commit comments

Comments
 (0)