Comment

Comment by fny

I never understood why a lot of this was never handled with metaprogramming. I feel like it might have something to do with Redux using constants and imports as a type safety hack, but all the ceremony drives me nuts.

First we enumerate our actions as constants...

    const ADD_TODO = 'ADD_TODO'
Then we need to create an "action creator" somewhere:

    import { ADD_TODO } from '../actionTypes'

    function addTodo(text) {
      return {
        type: ADD_TODO,
        text
      }
    }
Then we need to import that action and dispatch it when we need it...

    import addTodo from './actions'

    dispatch(addTodo(text))
Now even the same nonsense for reducers...
parent fny 9 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton