Comment

Comment by bcheung

Love this article. I gave an internal talk recently that was about the sad state of programming right now.

How we used to set a variable in assembly language:

  mov [foo], ax
How we do it in React / Redux

  // constants.js
  export const SET_FOO = 'SET_FOO'


  // actions.js
  import { SET_FOO } from './constants'

  export const setFoo = foo => ({ type: SET_FOO, payload: foo })


  // reducer.js
  import { SET_FOO } from './constants'

  const initialState = { foo: 0 }

  const reducer = (state = initialState, action) => {
    const { type, payload } = action
    switch (type) {
      case SET_FOO:
        return { ...state, foo: payload }
       
      default:
        return state
  }

  export default reducer


  // Component.js
  import { connect } from 'react-redux'
  import { setFoo } from './actions'

  class Component extends React.Component {
    handleSetFoo = foo => {
      this.props.dispatch(setFoo(foo))
    }
  }

  export default connect()(Component)

I don't understand how people don't see something is horribly wrong.
parent bcheung 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton