Guest User

Untitled

a guest
Nov 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. # How to use View-Models
  2.  
  3. ... The introductory text of the reactive UI and isomorphic applications
  4.  
  5. [Image]
  6.  
  7. ## Basic concept
  8.  
  9. View model is a read model or part of it that represent a part of UI state and can live on client. It can be updated by Redux reducer function on the client and on the server.
  10.  
  11. ## Type Reference "ViewModel"
  12.  
  13. ```
  14. type ViewModel = {
  15. name: String
  16. projection: {
  17. Init: Void -> State
  18. [EventType]: (State, Event) -> State
  19. ...
  20. }
  21. serializeState: State -> String
  22. deserializeState: String -> State
  23. }
  24. ```
  25.  
  26. ```
  27. type State = Immutable<Object|Array>
  28. ```
  29.  
  30. ```
  31. type Event = {
  32. aggregateId: UUID
  33. timestamp: Date
  34. type: EventType
  35. }
  36. ```
  37.  
  38. ```
  39. type EventType = String
  40. ```
  41.  
  42. ## How its working on client-side with Redux
  43.  
  44. 1. Get Initial State by viewModel (eventTypes) + aggregateId. Initial State -> ViewModels Reducer
  45. 2. Subscribe on Events by viewModel (eventTypes) + aggregateId. Store.dispatch(event)
  46.  
  47. ...
  48.  
  49. ## How its working on server-side with ReSolve
  50.  
  51. 1. Query get Events by viewModel (eventTypes) + aggregateId. Events -> ViewModels Reducer -> Client
  52. 2. Bus get Events by viewModel (eventTypes) + aggregateId. Events -> Socket.emit(events) -> Client
  53.  
  54. ...
  55.  
  56. ## TL;DR
  57. * Link to Github "ToDo App"
  58. * Link to Github "Two Level ToDo App"
  59.  
  60. ## Code Examples
  61. * ToDo App
  62. * UI
  63. * Aggregates
  64. * View-models
  65.  
  66. * Two Level ToDo App
  67. * UI
  68. * Routing
  69. * Index
  70. * Todo
  71. * Aggregates
  72. * View-models
  73.  
  74. ## Conclusion
  75. * Text
  76. * Fork/Star me on Github
  77.  
  78. ## Links
  79. * Link to Github "ReSolve"
  80. * Link to Github "Create-resolve-app"
  81. * Link to Github "EventStore"
  82. * Link to Github "View-models"
  83. * Link to Github "Aggregates"
  84. * Link to ReSolve Medium
  85. * Link to ReSolve Twitter
  86. * Link to ReSolve Facebook
Add Comment
Please, Sign In to add comment