react-native-navigation的迁移库

MyStore.js 743B

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