Skip to content

Commit a392bf9

Browse files
authored
Adding jsdocs for universal storage (#730)
1 parent 5044dbc commit a392bf9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.changeset/odd-oranges-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Adding jsdocs for universal storage

packages/browser/src/core/user/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
233233
- value exist in one of the stores ( as a result of other stores being cleared from browser ) and we want to resync them
234234
- read values in AJS 1.0 format ( for customers after 1.0 --> 2.0 migration ) and then re-write them in AJS 2.0 format
235235
*/
236+
237+
/**
238+
* get value for the key from the stores. it will pick the first value found in the stores, and then sync the value to all the stores
239+
* if the found value is a number, it will be converted to a string. this is to support legacy behavior that existed in AJS 1.0
240+
* @param key key for the value to be retrieved
241+
* @param storeTypes optional array of store types to be used for performing get and sync
242+
* @returns value for the key or null if not found
243+
*/
236244
public getAndSync<K extends keyof Data>(
237245
key: K,
238246
storeTypes?: StoreType[]
@@ -247,6 +255,12 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
247255
) as Data[K] | null
248256
}
249257

258+
/**
259+
* get value for the key from the stores. it will return the first value found in the stores
260+
* @param key key for the value to be retrieved
261+
* @param storeTypes optional array of store types to be used for retrieving the value
262+
* @returns value for the key or null if not found
263+
*/
250264
public get<K extends keyof Data>(
251265
key: K,
252266
storeTypes?: StoreType[]
@@ -262,6 +276,13 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
262276
return null
263277
}
264278

279+
/**
280+
* it will set the value for the key in all the stores
281+
* @param key key for the value to be stored
282+
* @param value value to be stored
283+
* @param storeTypes optional array of store types to be used for storing the value
284+
* @returns value that was stored
285+
*/
265286
public set<K extends keyof Data>(
266287
key: K,
267288
value: Data[K] | null,
@@ -273,6 +294,11 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
273294
return value
274295
}
275296

297+
/**
298+
* remove the value for the key from all the stores
299+
* @param key key for the value to be removed
300+
* @param storeTypes optional array of store types to be used for removing the value
301+
*/
276302
public clear<K extends keyof Data>(key: K, storeTypes?: StoreType[]): void {
277303
for (const store of this.getStores(storeTypes)) {
278304
store.remove(key)

0 commit comments

Comments
 (0)