agilgur5 / agilgur5/mst-persist

Persist changed value from `true` to `false`

Open
#26 3 comments 0 reactions 0 assignees View on GitHub
kind: support solution: duplicate solution: intended behavior solution: needs test
Dominant language
TypeScript
Stars
86
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Hi.

## Environment info

React native info output:

```bash
System:
OS: Linux 5.3 Ubuntu 18.04.4 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory: 12.78 GB / 31.23 GB
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 12.16.1 - /usr/bin/node
Yarn: 1.21.1 - /usr/bin/yarn
npm: 6.13.4 - /usr/bin/npm
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5

```

The problem is, when i persist RootStore with nested AuthStore, all my boolean value form AuthStore become from `true` to `false`.

When i just console.log its value, i have this behaviour
```javascript
const { isLoading } = authStore;

console.log('isLoading => ', isLoading);
```
![image](https://user-images.githubusercontent.com/19660005/75380769-973f1a80-5912-11ea-86d9-4686fd59460e.png)

It is RootStore with nested AuthStore
```javascript
import { types } from 'mobx-state-tree';
import { connectReduxDevtools } from 'mst-middlewares';
import AuthStore from './auth.store';
import { persist } from 'mst-persist';
import AsyncStorage from '@react-native-community/async-storage';

let store: any = null;

export default () => {
if (store) return store;

const RootStore = types
.model('RootStore', {
identifier: types.optional(types.identifier, 'RootStore'),
auth: AuthStore,
});

store = RootStore.create({
auth: {
isLoading: true,
},
});

/**
* Not working in debug mode
*/
persist('rootStore', store, {
storage: AsyncStorage,
}).then(() => {});

// @ts-ignore
if (__DEV__ && Boolean(window.navigator.userAgent)) {
connectReduxDevtools(require('remotedev'), store);
}

return store;
};
```
There is AuthStore
```javascript
import { types } from 'mobx-state-tree';
const AuthStore = types
.model({
isLoading: types.optional(types.boolean, true),
});

export default AuthStore;
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.