# cerebral-async-storage

> Async storage provider for Cerebral

Latest version **1.1.2** (published 2017-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install cerebral-async-storage
pnpm add cerebral-async-storage
yarn add cerebral-async-storage
bun add cerebral-async-storage
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2017-09-27 |
| First published | 2017-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shishkin Ivan |
| Maintainers | gibson |
| Keywords | cerebral, react-native, async storage |

## Links

- npm: https://www.npmjs.com/package/cerebral-async-storage
- Repository: https://github.com/gibson/cerebral-async-storage
- Homepage: https://github.com/gibson/cerebral-async-storage#readme
- Issues: https://github.com/gibson/cerebral-async-storage/issues
- npm.io page: https://npm.io/package/cerebral-async-storage

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2017-09-27
- 1.1.1 — 2017-09-27
- 1.1.0 — 2017-09-27
- 1.0.5 — 2017-09-26

## README

# cerebral async storage

## Install
**NPM**

`npm install cerebral-async-storage`

## Description
This module exposes react-native async storage as a provider,
where it by default parses and serializes to JSON.

The main feature - you can synchronize your app state with async storage and auto restore state on app starting.

## Instantiate

```js
import {Controller} from 'cerebral'
import StorageProvider from 'cerebral-async-storage'

const controller = Controller({
  providers: [StorageProvider({
    // Set prefix for your application, its optional
    prefix: 'somePrefix'
  })]
})
```
## Auto sync
For sync your state you need run signal:
```javascript
import {restoreState} from 'cerebral-async-storage/operators';

controller.runSignal('$NAME$', [restoreState]);
```

# Base actions
## get
Get data from storage.

*action*
```javascript
function someAction({asyncStorage}) {
  const data = asyncStorage.get('someKey')
}
```

*operator*
```javascript
import {state, props} from 'cerebral/tags'
import {getStorage} from 'cerebral-async-storage/operators'

export default [
  getStorage('someKey'),
  function someAction ({props}) {
    props.value // Whatever was on "someKey"
  }
]
```

## remove
Remove data from storage.

*action*
```javascript
function someAction({asyncStorage}) {
  asyncStorage.remove('someKey')
}
```

*operator*
```javascript
import {state} from 'cerebral/tags'
import {removeStorage} from 'cerebral-async-storage/operators'

export default [
  removeStorage(state`currentStorageKey`)
]
```

## set
Write data to storage.

*action*
```javascript
function someAction({asyncStorage}) {
  asyncStorage.set('someKey', {foo: 'bar'})
}
```

*operator*
```javascript
import {state, props} from 'cerebral/tags'
import {setStorage} from 'cerebral-async-storage/operators'

export default [
  setStorage(state`currentStorageKey`, props`someData`)
]
```

---
_Source: https://npm.io/package/cerebral-async-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
