# redux-persist-model

> Immutable Model for Redux Persist

Latest version **0.1.4** (published 2017-06-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install redux-persist-model
pnpm add redux-persist-model
yarn add redux-persist-model
bun add redux-persist-model
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2017-06-25 |
| First published | 2017-04-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Henry Tao |
| Maintainers | henrytao |
| Keywords | redux, persist, model, immutable |

## Links

- npm: https://www.npmjs.com/package/redux-persist-model
- Repository: https://github.com/henrytao-me/redux-persist-model
- Homepage: https://github.com/henrytao-me/redux-persist-model#readme
- Issues: https://github.com/henrytao-me/redux-persist-model/issues
- npm.io page: https://npm.io/package/redux-persist-model

## Dependencies (1)

- [immutable](https://npm.io/package/immutable.md) 3.8.1

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2017-06-25
- 0.1.3 — 2017-06-24
- 0.1.2 — 2017-06-24
- 0.1.1 — 2017-06-24
- 0.1.0 — 2017-06-24
- 0.0.1 — 2017-04-14

## README

# redux-persist-model

Immutable Model for Redux Persist - backed by [Record Immutable](https://facebook.github.io/immutable-js/docs/#/Record)

## Installation

```js
npm install redux-persist-model --save
```

## Usages

### Define Model

```js
// user.js
import { Model } from 'redux-persist-model'

const Base = Model.create('User', {
  id: undefined,
  firstName: 'default-value',
  lastName: 'default-value',
  username: 'default-value'
})

export default class User extends Base {
  
  getFullName() {
    return `${this.firstName} ${this.lastName}` 
  }
}
```

### Use Model

```js
const user = new User({
  id: 'some-user-id',
  firstName: 'user-first-name',
  lastName: 'user-last-name',
  username: 'user-name'
})

user.firstName
user.lastName
user.getFullName()
user.get('firstName')
user.get('firstName', 'default-value')
```

### Integrate with redux-persist using applyModelTransform

```js
// store.js
import { AsyncStorage } from 'react-native'
import { persistStore } from 'redux-persist'
import { applyModelTransform } from 'redux-persist-model'

import UserModel from './user'

const MODELS = [UserModel, ...SomeOtherModels]
const STORE = ...

persistStore(STORE, {
  storage: AsyncStorage,
  transforms: [applyModelTransform(MODELS)]
})
```

### Lazy load component with PersistModelProvider

If you want to wait until redux-persist is rehydrated before rendering components to UI, you can use `PersistModelProvider`

```js
// store.js
import { AsyncStorage } from 'react-native'
import { persistStore } from 'redux-persist'
import { applyModelTransform, PersistModelProvider } from 'redux-persist-model'

import UserModel from './user'

const MODELS = [UserModel, ...SomeOtherModels]
const STORE = ...

persistStore(STORE, {
  storage: AsyncStorage,
  transforms: [applyModelTransform(MODELS)]
}, () => PersistModelProvider.rehydrated())

// main.js
import { Provider } from 'react-redux'
import { PersistModelProvider } from 'redux-persist-model'

import HomeComponent './home'

export default class Main extends PureComponent {

  render() {
    return (
      <Provider store={STORE}>
        <PersistModelProvider>
          <HomeComponent />
        </PersistModelProvider>
      </Provider>
    )
  }
}
```


## License

    Copyright 2017 "Henry Tao <hi@henrytao.me>"

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

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