Browse Source

125 - Adding Redux

Elisa Cutrin 1 year ago
parent
commit
6e916ffc30

+ 7 - 11
App.js

@@ -1,27 +1,23 @@
1 1
 import React from 'react';
2
-import { StyleSheet, Text, View } from 'react-native';
3 2
 import {
3
+  NavigationContext,
4 4
   NavigationProvider,
5 5
   StackNavigation,
6 6
 } from '@expo/ex-navigation';
7 7
 import Router from './Router';
8
+import Store from './application/redux/store';
8 9
 
10
+const navigationContext = new NavigationContext({
11
+  router: Router,
12
+  store: Store
13
+});
9 14
 
10 15
 export default class App extends React.Component {
11 16
   render() {
12 17
     return (
13
-      <NavigationProvider router={Router}>
18
+      <NavigationProvider context={navigationContext}>
14 19
         <StackNavigation initialRoute={Router.getRoute('hello')} />
15 20
       </NavigationProvider>
16 21
     );
17 22
   }
18 23
 };
19
-
20
-const styles = StyleSheet.create({
21
-  container: {
22
-    flex: 1,
23
-    backgroundColor: '#fff',
24
-    alignItems: 'center',
25
-    justifyContent: 'center',
26
-  },
27
-});

+ 0 - 0
application/redux/actions/actions.js


+ 0 - 0
application/redux/reducers/reducers.js


+ 17 - 0
application/redux/store.js

@@ -0,0 +1,17 @@
1
+import { createNavigationEnabledStore, NavigationReducer } from '@expo/ex-navigation';
2
+import { combineReducers, createStore } from 'redux';
3
+
4
+const createStoreWithNavigation = createNavigationEnabledStore({
5
+  createStore,
6
+  navigationStateKey: 'navigation',
7
+});
8
+
9
+const Store = createStoreWithNavigation(
10
+  /* combineReducers and your normal create store things here! */
11
+  combineReducers({
12
+    navigation: NavigationReducer,
13
+    // other reducers
14
+  })
15
+);
16
+
17
+export default Store;

+ 37 - 5
package-lock.json

@@ -625,6 +625,22 @@
625 625
           "version": "1.2.0",
626 626
           "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz",
627 627
           "integrity": "sha1-qkSM8JhtVcxAdzsXF0t90GbLfPs="
628
+        },
629
+        "redux": {
630
+          "version": "3.7.2",
631
+          "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz",
632
+          "integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==",
633
+          "requires": {
634
+            "lodash": "4.17.5",
635
+            "lodash-es": "4.17.8",
636
+            "loose-envify": "1.3.1",
637
+            "symbol-observable": "1.2.0"
638
+          }
639
+        },
640
+        "symbol-observable": {
641
+          "version": "1.2.0",
642
+          "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
643
+          "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ=="
628 644
         }
629 645
       }
630 646
     },
@@ -9262,12 +9278,10 @@
9262 9278
       }
9263 9279
     },
9264 9280
     "redux": {
9265
-      "version": "3.7.2",
9266
-      "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz",
9267
-      "integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==",
9281
+      "version": "4.0.0",
9282
+      "resolved": "https://registry.npmjs.org/redux/-/redux-4.0.0.tgz",
9283
+      "integrity": "sha512-NnnHF0h0WVE/hXyrB6OlX67LYRuaf/rJcbWvnHHEPCF/Xa/AZpwhs/20WyqzQae5x4SD2F9nPObgBh2rxAgLiA==",
9268 9284
       "requires": {
9269
-        "lodash": "4.17.5",
9270
-        "lodash-es": "4.17.8",
9271 9285
         "loose-envify": "1.3.1",
9272 9286
         "symbol-observable": "1.2.0"
9273 9287
       },
@@ -11816,6 +11830,24 @@
11816 11830
             "object-assign": "4.1.1",
11817 11831
             "prop-types": "15.6.1"
11818 11832
           }
11833
+        },
11834
+        "redux": {
11835
+          "version": "3.7.2",
11836
+          "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz",
11837
+          "integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==",
11838
+          "dev": true,
11839
+          "requires": {
11840
+            "lodash": "4.17.5",
11841
+            "lodash-es": "4.17.8",
11842
+            "loose-envify": "1.3.1",
11843
+            "symbol-observable": "1.2.0"
11844
+          }
11845
+        },
11846
+        "symbol-observable": {
11847
+          "version": "1.2.0",
11848
+          "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
11849
+          "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==",
11850
+          "dev": true
11819 11851
         }
11820 11852
       }
11821 11853
     },

+ 3 - 1
package.json

@@ -22,6 +22,8 @@
22 22
     "@expo/ex-navigation": "^4.2.0",
23 23
     "expo": "^26.0.0",
24 24
     "react": "16.3.0-alpha.1",
25
-    "react-native": "0.54.0"
25
+    "react-native": "0.54.0",
26
+    "react-redux": "^5.0.7",
27
+    "redux": "^4.0.0"
26 28
   }
27 29
 }