Skip to content

Commit e220bc4

Browse files
committed
addressing review comments
1 parent f54db93 commit e220bc4

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

packages/shared/sdk-server/src/api/subsystems/LDDataSourceUpdates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface LDDataSourceUpdates {
4848
* @param data An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
4949
* the value is an object that maps keys to entities. The actual type of this parameter is
5050
* `interfaces.FullDataSet<VersionedData>`.
51-
* @param selector TODO
51+
* @param selector opaque string that uniquely identifies the state that contains the changes
5252
* @param callback Will be called after the changes are applied.
5353
*/
5454
applyChanges(

packages/shared/sdk-server/src/api/subsystems/LDFeatureStore.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,16 @@ export interface LDFeatureStore {
138138
upsert(kind: DataKind, data: LDKeyedFeatureStoreItem, callback: () => void): void;
139139

140140
/**
141+
* Applies the provided data onto the existing data, replacing all data or upserting depending
142+
* on the basis parameter.
143+
*
141144
* @param basis If true, completely overwrites the current contents of the data store
142145
* with the provided data. If false, upserts the items in the provided data. Upserts
143146
* are made only if provided items have newer versions than existing items.
144147
* @param data An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
145148
* the value is an object that maps keys to entities. The actual type of this parameter is
146149
* `interfaces.FullDataSet<VersionedData>`.
147-
* @param selector TODO
150+
* @param selector opaque string that uniquely identifies the state that contains the changes
148151
* @param callback Will be called after the changes are applied.
149152
*/
150153
applyChanges(

packages/shared/sdk-server/src/store/InMemoryFeatureStore.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,25 @@ export default class InMemoryFeatureStore implements LDFeatureStore {
7070
applyChanges(
7171
basis: boolean,
7272
data: LDFeatureStoreDataStorage,
73-
selector: String | undefined, // TODO handle selector
73+
selector: String | undefined, // TODO: SDK-1044 - Utilize selector
7474
callback: () => void,
7575
): void {
7676
if (basis) {
7777
this._initCalled = true;
7878
this._allData = data;
7979
} else {
80+
const tempData: LDFeatureStoreDataStorage = {};
81+
// shallow copy to protect against concurrent read
82+
Object.entries(this._allData).forEach(([namespace, items]) => {
83+
tempData[namespace] = { ...items };
84+
});
85+
8086
Object.entries(data).forEach(([namespace, items]) => {
8187
Object.keys(items || {}).forEach((key) => {
82-
let existingItems = this._allData[namespace];
88+
let existingItems = tempData[namespace];
8389
if (!existingItems) {
8490
existingItems = {};
85-
this._allData[namespace] = existingItems;
91+
tempData[namespace] = existingItems;
8692
}
8793
const item = items[key];
8894
if (Object.hasOwnProperty.call(existingItems, key)) {
@@ -95,6 +101,8 @@ export default class InMemoryFeatureStore implements LDFeatureStore {
95101
}
96102
});
97103
});
104+
105+
this._allData = tempData;
98106
}
99107

100108
callback?.();

0 commit comments

Comments
 (0)