Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

assemble redux stuffs, merge actions and reducers in a single file. #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kaijun
Copy link

@Kaijun Kaijun commented Jan 15, 2016

I think it may be a better approach of combining actions and reducers in one file.

Action names will be implicitly declared as variables, so that the action and reducer are able to use the identical variable as their action names.

It's really easy to control the specific domain of actions and reducers. In the long term, when the action names are getting more and more and probably having naming conflict, redux dispatcher will go wrong.
But we can simply define the const variables by using Symbol instead of String, for example:

//previously
const ADD_TODO = 'add todo'
const DELETE_TODO = 'delete todo'
const EDIT_TODO = 'edit todo'
const COMPLETE_TODO = 'complete todo'
const COMPLETE_ALL = 'complete all'
const CLEAR_COMPLETE = 'clear complete'

//using Symbol
const ADD_TODO = Symbol('todo')
const DELETE_TODO = Symbol('todo')
const EDIT_TODO = Symbol('todo')
const COMPLETE_TODO = Symbol('todo')
const COMPLETE_ALL = Symbol('todo')
const CLEAR_COMPLETE = Symbol('todo')

Tested it works like a charm 😄

@tj
Copy link
Owner

tj commented Jan 15, 2016

Nice! I'll think about it. In some ways I like separate files, some of my actions get a little large, but in general this seems fine to me, having the constants there for reference is nice. The only thing I'd change is the dir names, not a huge fan of .the ./redux dir, not like we have a ./react dir etc.

@tj tj mentioned this pull request Jan 26, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants