redux 图解

image.png

redux-saga 图解

image.png

dva 图解

image.png

  1. // dva 模板
  2. import { Reducer, Effect, Subscription } from 'umi';
  3. interface ModelType {
  4. namespace: 'somename';
  5. state: {};
  6. reducers: {
  7. someReducerFn: Reducer;
  8. };
  9. effects: {
  10. effectFn: Effect;
  11. };
  12. subscriptions: {
  13. setup: Subscription;
  14. };
  15. }
  16. const someModel: ModelType = {
  17. namespace: 'somename',
  18. state: {},
  19. reducers: {
  20. someReducerFn(state, action) {
  21. // action = { type, payload }
  22. // 对 state 进行处理后返回 newState
  23. // return newState
  24. },
  25. },
  26. effects: {
  27. *effectFn(action, effects) {
  28. // effects = { put, call }
  29. // put 执行 reducers 中的方法
  30. // call 执行 srevice 请求
  31. // 没有返回值
  32. },
  33. },
  34. subscriptions: {
  35. setup({ dispatch, history }) {
  36. // dispatch(action)
  37. // 可以执行 effects / reducers 中的方法
  38. return history.listen(location => {
  39. if (location.pathname === 'someurl') {
  40. dispatch({
  41. type: 'someReducerFn',
  42. });
  43. }
  44. });
  45. },
  46. },
  47. };
  48. export default someModel;