Advertisement
bennyp

Untitled

Oct 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const activate = (step, key, collection) => ({
  2.   ...step,
  3.   active:
  4.     step.active === undefined &&
  5.     key === Object.keys(collection)[0]
  6.       ? true
  7.       : step.active
  8. })
  9.  
  10. const initSteps = (steps, step, index) => ({
  11.   ...steps,
  12.   [step]: {
  13.     active: index === 0,
  14.     completed: false,
  15.     validating: false,
  16.     validations: false,
  17.     data: null
  18.   }
  19. })
  20.  
  21. // mapValues should take data last for composability and curryability
  22. const activateTheStep = data =>
  23.   mapValues(cloneDeep(data), activate)
  24.  
  25. switch (action.type) {
  26.  
  27.   case 'FOO': return {
  28.     ...state,
  29.     Steps: {
  30.       this.stepData
  31.         ? activateTheStep(this.stepData)
  32.         : this.getSteps().reduce(initSteps, {})
  33.     }
  34.   }
  35.  
  36.   default: return state
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement