Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. const horeducer = (callback,...reducers) => (state, action) => {
  2. var fnamed ={}
  3. reducers.map( r => fnamed[r.name]=s=> r(s,action) )
  4. return callback(state,action,fnamed)
  5. }
  6.  
  7.  
  8.  
  9. const red1 = (state=0,action) =>{
  10. console.log("r1state");
  11. console.log(state)
  12. switch(action){
  13. case 'INC':
  14. return state+1
  15. case 'DEC':
  16. return state+1
  17. default:
  18. return state
  19. }
  20. }
  21.  
  22. var state1;
  23. console.log(red1(state1,'INC'))
  24.  
  25. const red2 = (state={a:0},action) =>{
  26. switch(action){
  27. case 'ADD2':
  28. state.a+=2
  29. return state
  30. default:
  31. state
  32. }
  33. }
  34.  
  35. var state2;
  36. console.log(red2(state2,'ADD2'))
  37.  
  38. const hored = (state, action, reducers) => {
  39. console.log(reducers[0](state))
  40. var s = {a:reducers[0](state)}
  41. return reducers[1](s)
  42. }
  43.  
  44. const hored2= (state, action, {red1,red2}) => {
  45. console.log(red1(state))
  46. var s = {a:red1(state)}
  47. return red2(s)
  48. }
  49.  
  50. var x = horeducer(hored2,red1,red2)
  51. console.log(x(1,'ADD2'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement