What if you push (almost) all the responsability to the actions?
You could tweak redux a little bit by writing a middleware.
const thunk = store => next => action => typeof action === 'function' ? next({type: '', state: action(store.getState)}) : next(action)
Then create a very generic reducer.
const reducer = function(state, action) { if(typeof action.state !== 'undefined') { return Object.assign({}, state, action.state) } return initialState() }
And now you can have actions like this:
let nextTodoId = 0 export const addTodo = text => state => { // complexity, my old friend, you can live here return { todos: state().todos.concat({ id: nextTodoId++, text, completed: false }) } } export const setVisibilityFilter = filter => state => ({ visibilityFilter: filter })
This has lots of potential! Thank you for sharing.
With a bit more tweaks this could be very clean for developers to use without much thought. I will play with this trick thanks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What if you push (almost) all the responsability to the actions?
You could tweak redux a little bit by writing a middleware.
Then create a very generic reducer.
And now you can have actions like this:
This has lots of potential! Thank you for sharing.
With a bit more tweaks this could be very clean for developers to use without much thought. I will play with this trick thanks!