Skip to content

Commit

Permalink
Enable data persistance for liked jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
daxapps committed Nov 29, 2017
1 parent 1c08db7 commit 45aef66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react-navigation": "^1.0.0-beta.21",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-persist": "^4.10.2",
"redux-thunk": "^2.2.0"
}
}
3 changes: 3 additions & 0 deletions reducers/likes_reducer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import _ from 'lodash';
import { REHYDRATE } from 'redux-persist/constants';
import {
LIKE_JOB,
CLEAR_LIKED_JOBS
} from '../actions/types';

export default function(state = [], action) {
switch (action.type) {
case REHYDRATE:
return action.payload.likedJobs || [];
case CLEAR_LIKED_JOBS:
return [];
case LIKE_JOB:
Expand Down
7 changes: 6 additions & 1 deletion store/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { createStore, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import { persistStore, autoRehydrate } from 'redux-persist';
import { AsyncStorage } from 'react-native';
import reducers from "../reducers";

const store = createStore(
reducers,
{},
compose(
applyMiddleware(thunk)
applyMiddleware(thunk),
autoRehydrate()
)
);

persistStore(store, { storage: AsyncStorage, whitelist: ['likedJobs'] });

export default store;

0 comments on commit 45aef66

Please sign in to comment.