Guest User

Untitled

a guest
Sep 11th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. Redux
  2. =====
  3.  
  4. State management library
  5.  
  6. designing state of user
  7.  
  8. list
  9. create user
  10. manage user
  11.  
  12. user:{
  13. users:[],
  14. user:{
  15. username:'',
  16. password:''
  17. },
  18. currentUserId:''
  19. }
  20.  
  21.  
  22. Three Principles
  23.  
  24. Single source of truth
  25. State is read-only
  26. The only way to change the state is to emit an action, an object describing what happened.
  27.  
  28. Changes are made with pure functions
  29.  
  30.  
  31. folder structure
  32. ================
  33.  
  34. actions/action creators
  35. reducers
  36. store
  37. read => store.getState()
  38. subscribe => store.subscribe(()=>console.log(''))
  39. dispatch => store.dispatch(action)
  40. container
  41. * place where dispatching actions
  42. components
  43. * dump to display data passed from container
  44. middlewares
  45. * custom middlewares
  46. * Thunk , Promise , SAGA
  47.  
  48. actions
  49. =======
  50.  
  51. type = 'LOGIN_ATTEMPT'
  52.  
  53.  
  54. createStore(
  55. reducer,
  56. middleware(
  57.  
  58. ),
  59. ini
  60. )
  61.  
  62.  
  63. Parts
  64. ====
  65. State
  66. * Represent data / model of the application
  67. * Entire application should contain single object
  68.  
  69.  
  70. Actions
  71. * a plain object that contains type and payload( optional )
  72. * async and sync
  73. * by default sync but async can possible with middlewares such as Thunk, Promise, Saga
  74.  
  75. ActionCreators
  76. * functions which trigger to manage the state
  77. * Data manipulataion is should be through actions
  78. * dispatch function will trigger action
  79.  
  80. Reducers
  81. * functions that accept current state and action but return new state (copy).
  82. * by combining multiple Reducers and then pass it to the store called reducer composition.
  83. * just for manipulate data using functional javascript
  84. * return existing state if reducer's action not match with any action passed.
  85.  
  86. ReducerComposition
  87. * for store we should pass a single reducer for that combinig is called
  88. * combineReducers for redux is used
  89.  
  90. Middlewares
  91. * is a function execute during action trigger
  92. * just like node js middlewares
  93.  
  94. Store
  95. * represent applications data
  96. * use createStoer()
  97. * inject in the component using Provier from 'react-redux'
  98. * store.subscribe(). store.getState()
  99.  
  100. ContainerComponent
  101. * component that contain logics to subscripe data from store
  102.  
  103. PresentationalComponent
  104. * display data from ContainerComponent.
Add Comment
Please, Sign In to add comment