Skip to content

Commit adf9047

Browse files
committed
fix: remove warning about multiMerge not being implemented
1 parent 49dea24 commit adf9047

File tree

5 files changed

+6
-45
lines changed

5 files changed

+6
-45
lines changed

src/AsyncStorage.native.ts

-10
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ const AsyncStorage = ((): AsyncStorageStatic => {
118118
* Merges an existing `key` value with an input value, assuming both values
119119
* are stringified JSON.
120120
*
121-
* **NOTE:** This is not supported by all native implementations.
122-
*
123121
* See https://react-native-async-storage.github.io/async-storage/docs/api#mergeitem
124122
*/
125123
mergeItem: (key, value, callback) => {
@@ -337,8 +335,6 @@ const AsyncStorage = ((): AsyncStorageStatic => {
337335
* Batch operation to merge in existing and new values for a given set of
338336
* keys. This assumes that the values are stringified JSON.
339337
*
340-
* **NOTE**: This is not supported by all native implementations.
341-
*
342338
* See https://react-native-async-storage.github.io/async-storage/docs/api#multimerge
343339
*/
344340
multiMerge: (keyValuePairs, callback) => {
@@ -357,10 +353,4 @@ const AsyncStorage = ((): AsyncStorageStatic => {
357353
};
358354
})();
359355

360-
// Not all native implementations support merge.
361-
if (!RCTAsyncStorage.multiMerge) {
362-
delete AsyncStorage.mergeItem;
363-
delete AsyncStorage.multiMerge;
364-
}
365-
366356
export default AsyncStorage;

src/AsyncStorage.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ const AsyncStorage: AsyncStorageStatic = {
163163
* multiMerge([['k1', 'val1'], ['k2', 'val2']])
164164
*/
165165
multiMerge: (keyValuePairs, callback) => {
166-
const promises = keyValuePairs.map(
167-
(item) =>
168-
AsyncStorage.mergeItem?.(item[0], item[1]) ??
169-
Promise.reject('Not implemented')
166+
const promises = keyValuePairs.map((item) =>
167+
AsyncStorage.mergeItem(item[0], item[1])
170168
);
171169
return createPromiseAll(promises, callback);
172170
},

src/hooks.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export function useAsyncStorage(key: string): AsyncStorageHook {
55
return {
66
getItem: (...args) => AsyncStorage.getItem(key, ...args),
77
setItem: (...args) => AsyncStorage.setItem(key, ...args),
8-
mergeItem: (...args) =>
9-
AsyncStorage.mergeItem?.(key, ...args) ??
10-
Promise.reject('Not implemented'),
8+
mergeItem: (...args) => AsyncStorage.mergeItem(key, ...args),
119
removeItem: (...args) => AsyncStorage.removeItem(key, ...args),
1210
};
1311
}

src/types.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,9 @@ export type AsyncStorageStatic = {
7070
* Merges an existing `key` value with an input value, assuming both values
7171
* are stringified JSON.
7272
*
73-
* **NOTE:** This is not supported by all native implementations.
74-
*
7573
* See https://react-native-async-storage.github.io/async-storage/docs/api#mergeitem
7674
*/
77-
mergeItem?: (
78-
key: string,
79-
value: string,
80-
callback?: Callback
81-
) => Promise<void>;
75+
mergeItem: (key: string, value: string, callback?: Callback) => Promise<void>;
8276

8377
/**
8478
* Erases *all* `AsyncStorage` for all clients, libraries, etc. You probably
@@ -152,11 +146,9 @@ export type AsyncStorageStatic = {
152146
* Batch operation to merge in existing and new values for a given set of
153147
* keys. This assumes that the values are stringified JSON.
154148
*
155-
* **NOTE**: This is not supported by all native implementations.
156-
*
157149
* See https://react-native-async-storage.github.io/async-storage/docs/api#multimerge
158150
*/
159-
multiMerge?: (
151+
multiMerge: (
160152
keyValuePairs: [string, string][],
161153
callback?: MultiCallback
162154
) => Promise<void>;

website/docs/API.md

+1-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static getItem(key: string, [callback]: ?(error: ?Error, result: ?string) => voi
3030
**Example**:
3131
3232
```js
33-
3433
getMyStringValue = async () => {
3534
try {
3635
return await AsyncStorage.getItem('@key')
@@ -39,12 +38,10 @@ getMyStringValue = async () => {
3938
}
4039

4140
console.log('Done.')
42-
4341
}
4442
```
4543
4644
```js
47-
4845
getMyObject = async () => {
4946
try {
5047
const jsonValue = await AsyncStorage.getItem('@key')
@@ -54,7 +51,6 @@ getMyObject = async () => {
5451
}
5552

5653
console.log('Done.')
57-
5854
}
5955
```
6056
@@ -66,7 +62,7 @@ getMyObject = async () => {
6662
6763
## `setItem`
6864
69-
Sets a string `value` for given `key`. This operation can either modify an existing entry, if it did exist for given `key`, or add new one otherwise.
65+
Sets a string `value` for given `key`. This operation can either modify an existing entry, if it did exist for given `key`, or add new one otherwise.
7066
7167
In order to store object value, you need to serialize it, e.g. using `JSON.stringify()`.
7268
@@ -87,7 +83,6 @@ static setItem(key: string, value: string, [callback]: ?(error: ?Error) => void)
8783
**Example**:
8884
8985
```js
90-
9186
setStringValue = async (value) => {
9287
try {
9388
await AsyncStorage.setItem('key', value)
@@ -100,7 +95,6 @@ setStringValue = async (value) => {
10095
```
10196
10297
```js
103-
10498
setObjectValue = async (value) => {
10599
try {
106100
const jsonValue = JSON.stringify(value)
@@ -121,7 +115,6 @@ setObjectValue = async (value) => {
121115
## `mergeItem`
122116
123117
Merges an existing value stored under `key`, with new `value`, assuming both values are **stringified JSON**.
124-
**NOTE**: This is not supported by all native implementations.
125118
126119
**Signature**:
127120
@@ -180,7 +173,6 @@ mergeUsers = async () => {
180173
// }
181174
}
182175
}
183-
184176
```
185177
186178
<br />
@@ -242,7 +234,6 @@ static getAllKeys([callback]: ?(error: ?Error, keys: ?Array<string>) => void): P
242234
**Example**:
243235
244236
```js
245-
246237
getAllKeys = async () => {
247238
let keys = []
248239
try {
@@ -255,7 +246,6 @@ getAllKeys = async () => {
255246
// example console.log result:
256247
// ['@MyApp_user', '@MyApp_key']
257248
}
258-
259249
```
260250
261251
<br />
@@ -281,7 +271,6 @@ static multiGet(keys: Array<string>, [callback]: ?(errors: ?Array<Error>, result
281271
**Example**:
282272
283273
```js
284-
285274
getMultiple = async () => {
286275

287276
let values
@@ -295,7 +284,6 @@ getMultiple = async () => {
295284
// example console.log output:
296285
// [ ['@MyApp_user', 'myUserValue'], ['@MyApp_key', 'myKeyValue'] ]
297286
}
298-
299287
```
300288
301289
<br />
@@ -321,7 +309,6 @@ static multiSet(keyValuePairs: Array<Array<string>>, [callback]: ?(errors: ?Arra
321309
**Example**:
322310
323311
```js
324-
325312
multiSet = async () => {
326313
const firstPair = ["@MyApp_user", "value_1"]
327314
const secondPair = ["@MyApp_key", "value_2"]
@@ -333,7 +320,6 @@ multiSet = async () => {
333320

334321
console.log("Done.")
335322
}
336-
337323
```
338324
339325
<br />
@@ -344,7 +330,6 @@ multiSet = async () => {
344330
## `multiMerge`
345331
346332
Multiple merging of existing and new values in a batch. Assumes that values are *stringified JSON*. Once completed, invokes `callback` with errors (if any).
347-
**NOTE**: This is not supported by all native implementations.
348333
349334
**Signature**:
350335
@@ -430,7 +415,6 @@ mergeMultiple = async () => {
430415
// ]
431416
// ]
432417
}
433-
434418
```
435419
436420
@@ -501,7 +485,6 @@ clearAll = async () => {
501485

502486
console.log('Done.')
503487
}
504-
505488
```
506489
507490
<!-- ------------------------ HOOKS ------------------------ -->

0 commit comments

Comments
 (0)