react-native-navigation的迁移库

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const redux = require('redux');
  2. const _ = require('lodash');
  3. const initialState = {
  4. person: {
  5. name: 'no name'
  6. }
  7. };
  8. const reducer = (state = initialState, action) => {
  9. switch (action.type) {
  10. case 'redux.MyStore.setName': {
  11. return _.merge({}, state, { person: { name: action.name } });
  12. }
  13. case 'redux.MyStore.setAge': {
  14. return _.merge({}, state, { person: { age: action.age } });
  15. }
  16. default: {
  17. return state;
  18. }
  19. }
  20. };
  21. const selectors = {
  22. getName(state) {
  23. return _.get(state, 'person.name');
  24. },
  25. getAge(state) {
  26. return state.person.age;
  27. }
  28. };
  29. const reduxStore = redux.createStore(reducer);
  30. module.exports = {
  31. reduxStore,
  32. selectors
  33. };