Skip to content

Instantly share code, notes, and snippets.

@ajiehatajie
Created October 22, 2021 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajiehatajie/037abffb4c0ead8e2382dd80b4170d76 to your computer and use it in GitHub Desktop.
Save ajiehatajie/037abffb4c0ead8e2382dd80b4170d76 to your computer and use it in GitHub Desktop.
Redux persistor
import {combineReducers} from 'redux';
import {persistReducer} from 'redux-persist';
import AsyncStorage from '@react-native-community/async-storage';
import FSStorage from 'redux-persist-fs-storage';
import createSensitiveStorage from 'redux-persist-sensitive-storage';
import {reducer as WorkOrderReducer} from '../modules/WorkOrder/WorkOrderReducer';
import {reducer as AuthReducer} from '../modules/Auth/AuthReducer';
import {reducer as CustomerReducer} from '../modules/Customer/CustomerReducer';
import {reducer as ServiceVehicleReducer} from '../modules/ServiceVehicle/ServiceVehicleReducer';
import {reducer as NetworkReducer} from '../modules/Network/NetworkReducer';
import {reducer as ServiceLookupReducer} from '../modules/ServiceLookup/ServiceLookupReducer';
import {reducer as PartReducer} from '../modules/Part/PartReducer';
import {reducer as PostingReducer} from '../modules/Posting/PostingReducer';
import {reducer as ContactReducer} from '../modules/Contact/ContactReducer';
import {reducer as DarkModeReducer} from '../modules/DarkMode/DarkModeReducer';
import {reducer as DeviceReducer} from '../modules/Device/DeviceReducer';
import {reducer as EmployeeReducer} from '../modules/Employee/EmployeeReducer';
import {reducer as HistoryServiceReducer} from '../modules/HistoryService/HistoryServiceReducer';
import {reducer as JobAssignmentReducer} from '../modules/JobAssignment/JobAssignmentReducer';
const sensitiveStorage = createSensitiveStorage({
keychainService: 'bintangH2Keychain',
sharedPreferencesName: 'bintangH2SharedPrefs',
});
const authPersistConfig = {
key: 'auth',
storage: sensitiveStorage,
blacklist: ['password'],
};
const woPersistConfig = {
key: 'WorkOrder',
storage: FSStorage(),
blacklist: ['refreshImage'],
keyPrefix: '', //fix for fs storage path
};
const darkModePersistConfig = {
key: 'darkMode',
storage: AsyncStorage,
blacklist: ['loading'],
};
const partPersistConfig = {
key: 'part',
storage: AsyncStorage,
blacklist: ['loading'],
};
const servicePersistConfig = {
key: 'service',
storage: AsyncStorage,
blacklist: ['loading'],
};
const postingPersistConfig = {
key: 'posting',
storage: AsyncStorage,
blacklist: ['loading'],
};
const contactPersistConfig = {
key: 'contact',
storage: AsyncStorage,
blacklist: ['loading'],
};
const customerPersistConfig = {
key: 'customer',
storage: AsyncStorage,
blacklist: ['loading'],
};
const serviceLookupPersistConfig = {
key: 'serviceLookup',
storage: AsyncStorage,
blacklist: ['loading'],
};
const networkPersistConfig = {
key: 'network',
storage: AsyncStorage,
blacklist: ['loading'],
};
const devicesPersistConfig = {
key: 'devices',
storage: AsyncStorage,
blacklist: ['loading'],
};
const employeePersistConfig = {
key: 'employee',
storage: AsyncStorage,
blacklist: ['loading'],
};
const historyPersistConfig = {
key: 'historyService',
storage: AsyncStorage,
blacklist: ['loader'],
};
const jobAssignmentPersistConfig = {
key: 'jobassignment',
storage: AsyncStorage,
blacklist: ['loader'],
};
//#region
const rootReducer = combineReducers({
Auth: persistReducer(authPersistConfig, AuthReducer),
WorkOrder: persistReducer(woPersistConfig, WorkOrderReducer),
Customer: persistReducer(customerPersistConfig, CustomerReducer),
ServiceVehicle: persistReducer(servicePersistConfig, ServiceVehicleReducer),
NetInfo: persistReducer(networkPersistConfig, NetworkReducer),
ServiceLookup: persistReducer(
serviceLookupPersistConfig,
ServiceLookupReducer,
),
Part: persistReducer(partPersistConfig, PartReducer),
Posting: persistReducer(postingPersistConfig, PostingReducer),
Contact: persistReducer(contactPersistConfig, ContactReducer),
App: persistReducer(darkModePersistConfig, DarkModeReducer),
Device: persistReducer(devicesPersistConfig, DeviceReducer),
Employee: persistReducer(employeePersistConfig, EmployeeReducer),
History: persistReducer(historyPersistConfig, HistoryServiceReducer),
JobAssignment: persistReducer(
jobAssignmentPersistConfig,
JobAssignmentReducer,
),
});
export default rootReducer;
//#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment