Add boilerplate for redux, redux-persist.

This commit is contained in:
Ceda EI 2020-03-16 07:53:03 +05:30
parent f13caa7cc7
commit b7d68bdf77
7 changed files with 101 additions and 9 deletions

17
configureStore.js Normal file
View File

@ -0,0 +1,17 @@
import { createStore } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import AsyncStorage from "@react-native-community/async-storage";
import rootReducer from "./reducers";
const persistConfig = {
key: "root",
storage: AsyncStorage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export default () => {
const store = createStore(persistedReducer);
const persistor = persistStore(store);
return { store, persistor };
};

View File

@ -1,12 +1,15 @@
/**
* @format
*/
import React from "react";
import {AppRegistry} from "react-native";
import App from "./App";
import {name as appName} from "./app.json";
import { DarkTheme, Provider } from "react-native-paper";
import { Provider as ReduxProvider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import configureStore from "./configureStore";
const { store, persistor } = configureStore();
console.log(store);
console.log(persistor);
const theme = {
...DarkTheme,
@ -20,9 +23,13 @@ const theme = {
export default function Main() {
return (
<Provider theme={theme}>
<App />
</Provider>
<ReduxProvider store={store}>
<PersistGate persistor={persistor}>
<Provider theme={theme}>
<App />
</Provider>
</PersistGate>
</ReduxProvider>
);
}

View File

@ -10,10 +10,14 @@
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "^1.8.1",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-paper": "^3.6.0",
"react-native-vector-icons": "^6.6.0"
"react-native-vector-icons": "^6.6.0",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-persist": "^6.0.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",

5
reducers/classes.js Normal file
View File

@ -0,0 +1,5 @@
export default function classes(state) {
if (typeof state === "undefined")
return [];
return state;
}

11
reducers/index.js Normal file
View File

@ -0,0 +1,11 @@
import { combineReducers } from "redux";
import timetable from "./timetable";
import classes from "./classes";
const rootReducer = combineReducers({
timetable,
classes
});
export default rootReducer;

14
reducers/timetable.js Normal file
View File

@ -0,0 +1,14 @@
export default function timetable(state) {
if (typeof state === "undefined")
// Array of days starting with Sunday
return [
[],
[],
[],
[],
[],
[],
[],
];
return state;
}

View File

@ -617,7 +617,7 @@
pirates "^4.0.0"
source-map-support "^0.5.16"
"@babel/runtime@^7.0.0", "@babel/runtime@^7.6.2", "@babel/runtime@^7.8.4":
"@babel/runtime@^7.0.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.2", "@babel/runtime@^7.8.4":
version "7.8.7"
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.7.tgz#8fefce9802db54881ba59f90bb28719b4996324d"
integrity sha512-+AATMUFppJDw6aiR5NVPHqIQBlV/Pj8wY/EZH+lmvRdUo9xBaz/rF3alAwFJQavvKfeOlPE7oaaDHVbcySbCsg==
@ -863,6 +863,11 @@
"@types/yargs" "^15.0.0"
chalk "^3.0.0"
"@react-native-community/async-storage@^1.8.1":
version "1.8.1"
resolved "https://registry.npmjs.org/@react-native-community/async-storage/-/async-storage-1.8.1.tgz#c93e69dcf948667b207e409b8039b7edf199159b"
integrity sha512-MA1fTp4SB7OOtDmNAwds6jIpiwwty1NIoFboWjEWkoyWW35zIuxlhHxD4joSy21aWEzUVwvv6JJ2hSsP/HTb7A==
"@react-native-community/cli-debugger-ui@^3.0.0":
version "3.0.0"
resolved "https://registry.npmjs.org/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-3.0.0.tgz#d01d08d1e5ddc1633d82c7d84d48fff07bd39416"
@ -5170,6 +5175,17 @@ react-native@0.61.5:
stacktrace-parser "^0.1.3"
whatwg-fetch "^3.0.0"
react-redux@^7.2.0:
version "7.2.0"
resolved "https://registry.npmjs.org/react-redux/-/react-redux-7.2.0.tgz#f970f62192b3981642fec46fd0db18a074fe879d"
integrity sha512-EvCAZYGfOLqwV7gh849xy9/pt55rJXPwmYvI4lilPM5rUT/1NxuuN59ipdBksRVSvz0KInbPnp4IfoXJXCqiDA==
dependencies:
"@babel/runtime" "^7.5.5"
hoist-non-react-statics "^3.3.0"
loose-envify "^1.4.0"
prop-types "^15.7.2"
react-is "^16.9.0"
react-refresh@^0.4.0:
version "0.4.2"
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.2.tgz#54a277a6caaac2803d88f1d6f13c1dcfbd81e334"
@ -5248,6 +5264,19 @@ realpath-native@^1.1.0:
dependencies:
util.promisify "^1.0.0"
redux-persist@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8"
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==
redux@^4.0.5:
version "4.0.5"
resolved "https://registry.npmjs.org/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==
dependencies:
loose-envify "^1.4.0"
symbol-observable "^1.2.0"
regenerate-unicode-properties@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e"
@ -5997,6 +6026,11 @@ symbol-observable@1.0.1:
resolved "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.1.tgz#8340fc4702c3122df5d22288f88283f513d3fdd4"
integrity sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ=
symbol-observable@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
symbol-tree@^3.2.2:
version "3.2.4"
resolved "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"