Skip to content

Commit 919189c

Browse files
author
Krzysztof Borowy
committed
docs: core
1 parent d05ccdd commit 919189c

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Async Storage
22

3-
A storage system for React Native.
3+
A persistent data storage solution for your next mobile, web or desktop application.
44

55
## Work in progress
66

@@ -10,8 +10,22 @@ If you're looking for published and operational Async Storage version, please ch
1010

1111
If you'd like to see the progress of v2, [please visit Project page.](https://github.com/react-native-community/async-storage/projects/1)
1212

13-
## Running Examples
13+
## Features
14+
15+
todo
16+
17+
## Documentation
18+
19+
todo
20+
21+
## Available storage backends
22+
23+
- [Legacy](./packages/storage-legacy/README.md)
24+
25+
26+
## License
27+
28+
MIT
1429

15-
### React Native
1630

1731

packages/core/README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,63 @@
11
# Async Storage Core
22

3-
Main Async Storage component.
3+
Public-facing API of Async Storage.
44

5-
## Installation
5+
## Install
66

77
```bash
88
$ yarn install @react-native-community/async-storage
99
```
1010

11-
## Usage
11+
## API
1212

13-
Use `AsyncStorageFactory` to create your Async Storage instance
1413

14+
### `AsyncStorageFactory`
15+
16+
A factory module for `AsyncStorage` instance with selected storage backend attached.
1517

16-
```typescript
1718

19+
```typescript
1820
// storage.js
1921

2022
import ASFactory from '@react-native-community/async-storage'
2123

2224
// use any available Storage Backend
2325
const storageBackend = new StorageBackend();
2426

25-
const mobileStorage = ASFactory.create(storageBackend);
27+
const mobileStorage = ASFactory.create(storageBackend, options);
2628

2729
export default mobileStorage;
2830
```
2931

30-
## Providing a storage model
3132

32-
You can provide a `Model` type when creating Async Storage, to have a fully typed storage.
33+
**Factory options**
34+
35+
`AsyncStorageFactory.create` accepts an options object, that enables additional features.
36+
37+
38+
- *logger*
39+
40+
```typescript
41+
type logger = ((action: LoggerAction) => void) | boolean;
42+
```
43+
44+
Used to log `AsyncStorage` method calls and used arguments.
45+
You can provide your own implementation or use provided default logger (enabled by default in DEV mode).
46+
47+
48+
- *errorHandler*
49+
50+
```typescript
51+
type errorHandler = ((error: Error | string) => void) | boolean;
52+
````
53+
54+
Used to report any errors thrown.
55+
You can provide your own implementation or use provided default error handler (enabled by default in DEV mode).
56+
57+
58+
**Providing a storage model**
59+
60+
If you know the structure of the stored data upfront, you can use the full potential of the type system, by providing a type argument to `AsyncStorageFactory.create<T>` method.
3361

3462

3563
```typescript
@@ -43,17 +71,19 @@ type StorageModel = {
4371
preferences: {
4472
darkModeEnabled: boolean;
4573
};
46-
subscribedChannels: Array<Channel>;
74+
subscribedChannels: Array<string>;
4775
onboardingCompleted: boolean;
4876
};
4977
5078
// use any available Storage Backend
5179
const storageBackend = new StorageBackend();
5280
81+
5382
const storage = ASFactory.create<StorageModel>(storageBackend);
5483
5584
```
5685

5786
## License
5887

59-
MIT.
88+
MIT
89+

packages/core/types/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ export type LoggerAction = {
110110
};
111111

112112
// Helper types
113-
114-
export type StorageModel<T> = T extends IStorageBackend<infer V> ? V : any;
115-
116113
export type EmptyStorageModel = {[key in symbol | number | string]: any};
117114

118115
export type StorageOptions = {

packages/storage-legacy/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Storage Backend: Legacy
2+
3+
todo

0 commit comments

Comments
 (0)