Skip to content

Commit

Permalink
Coorected hyrateTime typo and README
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-olom committed Feb 11, 2021
1 parent 3a1ba68 commit 37413bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import CreatePersistor, {PersistorWrapper} from 'hookstate-persist';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Product} from '../utils/types';

// for map/tree like state, wrap root state with Persist wrapper
// this gives you the benefit of validating the hydrateTime value
// for tree object state, wrap root state with Persist wrapper
// this gives you the benefit of validating the hydrateTime value is not null
const wrapped = PersistorWrapper({
cart: [] as Array<Product>,
user: {} as User,
Expand All @@ -44,10 +44,7 @@ const persistor = CreatePersistor({
// attach plugin and you're done
store.attach(persistor);


```


### Peristor options

```js
Expand All @@ -63,7 +60,6 @@ CreatePersistor {
## API

```js
export default store;
CreatePersistor(config: ICreatePersistor) // creates the peristence plugin
PersistorWrapper(state: State<S>) // Wrapps the root state. Do not use if root state is not map/tree like
```
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function CreatePersistor({key, engine, blacklist, whitelist}: ICreatePersistor)
id: PersistPluginId,
init: (s: State<StateValueAtRoot>) => {
const engineResponse = engine.getItem(key);
// hydate the state from async storage
// hyrateTime the state from async storage
Promise.resolve(engineResponse).then((res) => {
if (res) {
const store = JSON.parse(res);
s.merge(store);
}
s.merge({hydateTime: Date.now()});
s.merge({hyrateTime: Date.now()});
});

return {
Expand Down Expand Up @@ -67,10 +67,10 @@ function PersistorWrapper<S>(state: S) {
if (typeof state == 'object') {
return {
...state,
hydateTime: null,
hyrateTime: null,
};
}
throw new Error('This helper only works on object trees/maps');
throw new Error('This helper only works on object trees');
}

export default CreatePersistor;
Expand Down

0 comments on commit 37413bb

Please sign in to comment.