Skip to content

Commit fe8ceda

Browse files
committed
Added docs.
1 parent 2948130 commit fe8ceda

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ getData = async () => {
5454

5555
```
5656

57-
See docs for [api and more examples.](docs/API.md)
57+
See docs for [api and more examples](docs/API.md), and [some advanced usage](docs/AdvancedUsage.md).
5858

5959
## Contribution
6060

6161
See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
6262

6363
## License
6464

65-
MIT
65+
MIT

docs/AdvancedUsage.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Advanced Usage
2+
3+
## Integrating with Existing Storage Solutions in Hybrid Apps
4+
5+
### iOS
6+
7+
On iOS, AsyncStorage can be controlled by the hosting app via the delegate on
8+
`RNCAsyncStorage`:
9+
10+
```objc
11+
RNCAsyncStorage *asyncStorage = [bridge moduleForClass:[RNCAsyncStorage class]];
12+
asyncStorage.delegate = self;
13+
```
14+
15+
The delegate must conform to the protocol `RNCAsyncStorageDelegate`:
16+
17+
```objc
18+
- (void)allKeys:(RNCAsyncStorageResultCallback)block;
19+
```
20+
21+
Returns all keys currently stored. If none, an empty array is returned.
22+
Called by `getAllKeys` in JS.
23+
24+
<br />
25+
26+
```objc
27+
- (void)mergeValues:(NSArray<NSString *> *)values
28+
forKeys:(NSArray<NSString *> *)keys
29+
completion:(RNCAsyncStorageResultCallback)block;
30+
```
31+
32+
Merges values with the corresponding values stored at specified keys.
33+
Called by `mergeItem` and `multiMerge` in JS.
34+
35+
<br />
36+
37+
```objc
38+
- (void)removeAllValues:(RNCAsyncStorageCompletion)block;
39+
```
40+
41+
Removes all values from the store. Called by `clear` in JS.
42+
43+
<br />
44+
45+
```objc
46+
- (void)removeValuesForKeys:(NSArray<NSString *> *)keys
47+
completion:(RNCAsyncStorageResultCallback)block;
48+
```
49+
50+
Removes all values associated with specified keys.
51+
Called by `removeItem` and `multiRemove` in JS.
52+
53+
<br />
54+
55+
```objc
56+
- (void)setValues:(NSArray<NSString *> *)values
57+
forKeys:(NSArray<NSString *> *)keys
58+
completion:(RNCAsyncStorageResultCallback)block;
59+
```
60+
61+
Sets specified key-value pairs. Called by `setItem` and `multiSet` in JS.
62+
63+
<br />
64+
65+
```objc
66+
- (void)valuesForKeys:(NSArray<NSString *> *)keys
67+
completion:(RNCAsyncStorageResultCallback)block;
68+
```
69+
70+
Returns values associated with specified keys.
71+
Called by `getItem` and `multiGet` in JS.
72+
73+
<br />
74+
75+
```objc
76+
@optional
77+
@property (nonatomic, readonly, getter=isPassthrough) BOOL passthrough;
78+
```
79+
80+
**Optional:** Returns whether the delegate should be treated as a passthrough.
81+
This is useful for monitoring storage usage among other things. Returns `NO` by
82+
default.

ios/RNCAsyncStorageDelegate.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,59 @@ typedef void (^RNCAsyncStorageResultCallback)(NSArray<id<NSObject>> * valuesOrEr
1414

1515
@protocol RNCAsyncStorageDelegate <NSObject>
1616

17+
/*!
18+
* Returns all keys currently stored. If none, an empty array is returned.
19+
* @param block Block to call with result.
20+
*/
1721
- (void)allKeys:(RNCAsyncStorageResultCallback)block;
1822

23+
/*!
24+
* Merges values with the corresponding values stored at specified keys.
25+
* @param values Values to merge.
26+
* @param keys Keys to the values that should be merged with.
27+
* @param block Block to call with merged result.
28+
*/
1929
- (void)mergeValues:(NSArray<NSString *> *)values
2030
forKeys:(NSArray<NSString *> *)keys
2131
completion:(RNCAsyncStorageResultCallback)block;
2232

33+
/*!
34+
* Removes all values from the store.
35+
* @param block Block to call with result.
36+
*/
2337
- (void)removeAllValues:(RNCAsyncStorageCompletion)block;
2438

39+
/*!
40+
* Removes all values associated with specified keys.
41+
* @param keys Keys of values to remove.
42+
* @param block Block to call with result.
43+
*/
2544
- (void)removeValuesForKeys:(NSArray<NSString *> *)keys
2645
completion:(RNCAsyncStorageResultCallback)block;
2746

47+
/*!
48+
* Sets specified key-value pairs.
49+
* @param values Values to set.
50+
* @param keys Keys of specified values to set.
51+
* @param block Block to call with result.
52+
*/
2853
- (void)setValues:(NSArray<NSString *> *)values
2954
forKeys:(NSArray<NSString *> *)keys
3055
completion:(RNCAsyncStorageResultCallback)block;
3156

57+
/*!
58+
* Returns values associated with specified keys.
59+
* @param keys Keys of values to return.
60+
* @param block Block to call with result.
61+
*/
3262
- (void)valuesForKeys:(NSArray<NSString *> *)keys
3363
completion:(RNCAsyncStorageResultCallback)block;
3464

3565
@optional
3666

67+
/*!
68+
* Returns whether the delegate should be treated as a passthrough.
69+
*/
3770
@property (nonatomic, readonly, getter=isPassthrough) BOOL passthrough;
3871

3972
@end

0 commit comments

Comments
 (0)