Skip to content

Commit

Permalink
Fixes #691 - auto-migrate persisted state when newer version requires it
Browse files Browse the repository at this point in the history
  • Loading branch information
zdmc23 committed Jul 11, 2022
1 parent 05a81d4 commit 8cdc580
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 77 deletions.
8 changes: 0 additions & 8 deletions store/actions/cache.actions.js

This file was deleted.

11 changes: 0 additions & 11 deletions store/actions/user.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ export const USER_LOGOUT = "USER_LOGOUT";
export const USER_LOGOUT_SUCCESS = "USER_LOGOUT_SUCCESS";
export const USER_LOGOUT_FAILURE = "USER_LOGOUT_FAILURE";

export const USER_GET_PUSH_TOKEN = "USER_GET_PUSH_TOKEN";

export const USER_ADD_PUSH_TOKEN = "USER_ADD_PUSH_TOKEN";
export const USER_ADD_PUSH_TOKEN_RESPONSE = "USER_ADD_PUSH_TOKEN_RESPONSE";
export const USER_ADD_PUSH_TOKEN_SUCCESS = "USER_ADD_PUSH_TOKEN_SUCCESS";
export const USER_ADD_PUSH_TOKEN_FAILURE = "USER_ADD_PUSH_TOKEN_FAILURE";

export const SET_FILTER = "SET_FILTER";
export const SET_THEME = "SET_THEME";

Expand Down Expand Up @@ -68,10 +61,6 @@ export function setTheme(theme) {
return { type: SET_THEME, theme };
}

export function getPushToken() {
return { type: USER_GET_PUSH_TOKEN };
}

export function getUserInfo() {
return { type: GET_MY_USER_INFO };
}
Expand Down
25 changes: 0 additions & 25 deletions store/reducers/cache.reducer.js

This file was deleted.

10 changes: 0 additions & 10 deletions store/reducers/user.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const userDataInitialState = {
displayName: null,
locale: null,
id: null,
expoPushToken: null,
theme: null,
};
const initialState = {
Expand Down Expand Up @@ -115,15 +114,6 @@ export default function userReducer(state = initialState, action) {
error: action?.error,
loading: false,
};
//case actions.USER_GET_PUSH_TOKEN:
case actions.USER_ADD_PUSH_TOKEN:
return {
...newState,
userData: {
...newState?.userData,
expoPushToken: action?.expoPushToken,
},
};
case actions.USER_LOGOUT_SUCCESS:
return {
...initialState,
Expand Down
20 changes: 0 additions & 20 deletions store/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import { combineReducers } from "redux";

import authReducer from "./reducers/auth.reducer";
import cacheReducer from "./reducers/cache.reducer";
import i18nReducer from "./reducers/i18n.reducer";
import networkReducer from "./reducers/network.reducer";
import requestReducer from "./reducers/request.reducer";
import userReducer from "./reducers/user.reducer";

//import * as actions from "./rootActions";

//const combinedReducers = combineReducers({
const rootReducer = combineReducers({
authReducer,
i18nReducer,
networkReducer,
requestReducer,
userReducer,
cacheReducer,
});

// Handling REINITIALIZE_REDUX in each individual reducer reducer is better bc we can reset to initialState rather than completely undefined
/*
const rootReducer = (state, action) => {
switch (action.type) {
//case REHYDRATE:
// return state;
// Clear all data in redux store (reset to initial)
case actions.REINITIALIZE_REDUX:
return state = undefined;
default:
return combinedReducers(state, action);
};
};
*/
export default rootReducer;
7 changes: 4 additions & 3 deletions store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const persistConfig = {
// "requestReducer"
//],
migrate: createMigrate(migrations, { debug: false }),
// semver-ish 1-digit (major), 2-digit (minor), 1-digit (patch)
// 1101 -> v1.10.1 or 2050 -> v2.5
version: 1101,
// SemVer-ish format:
// 1-digit (major), 2-digit (minor), 1-digit (patch), 1-digit (version)
// 11011 -> v1.10.1.1 or 205 -> v2.5
version: 11012,
stateReconciler: hardSet,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
Expand Down

0 comments on commit 8cdc580

Please sign in to comment.