DEV Community

Discussion on: Flow control, short-circuit expressions and functional programming in JavaScript

Collapse
 
pengeszikra profile image
Peter Vivo

Yes you right. But what are you think about react reducer switch like this? :

const someReducer(state, {type, payload}) {
  switch (type) {
    case SET_SOME: return {...state, some: payload}
    case WORK_WITH_OTHER: return {...state, other: payload, some: false}
    // ... and so on
    default: return state;
  }
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
daslaf profile image
Osman Cea

Looks like a regular reducer to me... how is this related to what we were talking?

Thread Thread
 
pengeszikra profile image
Peter Vivo

reducer is looks same as ternary with two function, just case use one condition with many pure function.

Thread Thread
 
daslaf profile image
Osman Cea

Again, this is because you care about the result of the function. My take is: use statements for side effects and expressions for pure functions.