Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joe-re/async-storage-repl
AsyncStorageRepl provides you to access remote ReactNative application's AsyncStorage from your node REPL.
https://github.com/joe-re/async-storage-repl
async-storage node react-native repl
Last synced: 12 days ago
JSON representation
AsyncStorageRepl provides you to access remote ReactNative application's AsyncStorage from your node REPL.
- Host: GitHub
- URL: https://github.com/joe-re/async-storage-repl
- Owner: joe-re
- Created: 2017-05-07T20:12:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-14T09:56:42.000Z (almost 7 years ago)
- Last Synced: 2024-10-01T09:16:50.327Z (about 1 month ago)
- Topics: async-storage, node, react-native, repl
- Language: JavaScript
- Homepage:
- Size: 38.1 KB
- Stars: 36
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AsyncStorageREPL
AsyncStorageRepl provides you to access remote ReactNative application's AsyncStorage from your node REPL.
![gif](https://cloud.githubusercontent.com/assets/4954534/26222189/09924ee2-3c54-11e7-8247-ed15afa7cd31.gif)
```
npm i async-storage-repl -D
```# BasicUsage
1. Write bellow code in your ReactNative Application.
```js
import AsyncStorageREPL from 'async-storage-repl';
AsyncStorageREPL().connect();
```2. Start node REPL.
```sh
./node_modules/.bin/async-storage-repl
```3. Let's get access your ReactNative application's storage from your node REPL.
```sh
$ ./node_modules/.bin/async-storage-repl
> RNAsyncStorage.getItem('item1')
null
> RNAsyncStorage.setItem('item1', 'nice value!')
null
> RNAsyncStorage.getItem('item1')
'nice value!'
> RNAsyncStorage.getAllKeys()
[ 'reduxPersist:timeline',
'item1',
'reduxPersist:auth',
'reduxPersist:nav' ]
```# Example
[example](/example)
# API
## AsyncStorage APIs
AsyncStorageREPL provides RNAsyncStorage on your node REPL as a global object.
You can access [AsyncStorage's all APIs](https://facebook.github.io/react-native/docs/asyncstorage.html) via this object.- getAllKeys(): string[]
- getItem(key: string)
- setItem(key: string, value: string)
- removeItem(key: string)
- mergeItem(key: string, value: string)
- clear()
- flushGetRequests()
- multiGet(keys: string[])
- multiSet(keyValuePairs: string[][])
- multiRemove(keys: string[])
- multiMerge(keyValuePairs: string[][])AsyncStorageREPL's methods args are guaranteed type-safe by [flow-runtime](https://codemix.github.io/flow-runtime/).
```sh
> RNAsyncStorage.getItem(1)
RuntimeTypeError: key must be a stringExpected: string
Actual: number
```
## dump & load
You can save & load RN Application AsyncStorage data.
`dump()` provides you getting dump.
`load(string[][])` provides you loading dump.```sh
> const data = RNAsyncStorage.dump()
undefined
> data
[ [ 'comments', '["foo","bar","baz"]' ] ]
> fs.writeSync('./dump1.txt', JSON.stringify(data))
``````sh
> const data = JSON.parse(fs.readSync('./dump1.txt'))
> RNAsyncStorage.load(data)
null
```
# Advanced Usage## ReactNative side
AsyncStorageREPL() accepts an object with a host and port key.
Port key must be matched REPL side.
You don't need specify a host in case of running on a simulator.
but in case of runnning on a real device, specify your computer host.```js
AsyncStorageREPL({ host: 'localhost', port: 8080 }) // default
.connect();
```## REPL side
You can specify portNo --port option.
```sh
async-storage-repl --port 8080
```