router.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { delay, NavigationActions } from '../utils'
  2. import { routerReducer } from '../router'
  3. const actions = [
  4. NavigationActions.BACK,
  5. NavigationActions.INIT,
  6. NavigationActions.NAVIGATE,
  7. NavigationActions.RESET,
  8. NavigationActions.SET_PARAMS,
  9. NavigationActions.URI,
  10. NavigationActions.REPLACE,
  11. NavigationActions.INIT,
  12. // 添加下面内容
  13. NavigationActions.POP,
  14. NavigationActions.POP_TO_TOP,
  15. NavigationActions.PUSH,
  16. NavigationActions.COMPLETE_TRANSITION,
  17. ]
  18. export default {
  19. namespace: 'router',
  20. state: {
  21. ...routerReducer(),
  22. },
  23. reducers: {
  24. apply(state, { payload: action }) {
  25. return routerReducer(state, action)
  26. },
  27. },
  28. effects: {
  29. watch: [
  30. function* watch({ take, call, put }) {
  31. while (true) {
  32. const payload = yield take(actions)
  33. yield put({
  34. type: 'apply',
  35. payload,
  36. })
  37. // debounce, see https://github.com/react-community/react-navigation/issues/271
  38. if (payload.type === 'Navigation/NAVIGATE') {
  39. yield call(delay, 500)
  40. }
  41. }
  42. },
  43. { type: 'watcher' },
  44. ],
  45. },
  46. }