Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. **How do Raj and Redux compare performance wise?**
  2.  
  3. Raj is faster theoretically. In Redux you have N reducers that need to be iterated, in Raj you have a single update which can call sub graph updates (log N). Redux also can have multiple subscriptions whereas Raj doesn't have any. Looking at code size and the amount of work each project does and the list-vs-tree distribution of work, Raj should be better.
  4.  
  5. Also since (logic+view+data) assemble into Raj programs, it's easier to code-split and lazy-load. There's no definite story for how to do at in Redux. In Raj, you use `raj-spa` where a program can resolve from a promise.
  6.  
  7. **Is there a way to apply Raj to a backend state machine where there is no view?**
  8.  
  9. So `view` is mostly for apps with UIs. It is a side-effect that receives the whole state as opposed to plain effects which need portions of state explicitly passed. If you don't need a view, you can think of it like a "window" into the current state. For example, you can have something like `tapProgram` which leverages `view` to log state changes:
  10.  
  11. ```js
  12. function tapProgram (program, onChange) {
  13. return {
  14. ...program,
  15. view (model, dispatch) {
  16. onChange(model)
  17. return program.view(model, dispatch)
  18. }
  19. }
  20. }
  21. ```
  22.  
  23. Raj can be used as a state machine alone.
  24. The reason view is not optional is because then every HOP would need to do that safety check.
  25. Since `view: () => {}` is valid, it's better to just let that be a required function in the interface even if it is only a no-op.
  26.  
  27. There is the optional `done` and the if-exists check on that is tedious.
  28. So tedious that it was important to make `raj-subscription` to handle those cases for us automatically.
  29.  
  30. I'm also not opposed to a `raj-viewless` function:
  31. ```js
  32. const viewless = program => ({ ...program, view: () => {} })
  33. ```
  34.  
  35. Or something that wraps the runtime itself.
  36. Since it is a choke-point you can stop all view calls with a HOP.
Add Comment
Please, Sign In to add comment