-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Use redux constants and action creator functions #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use redux constants and action creator functions #120
Conversation
365a8ff
to
d125770
Compare
In general I am in support of this change, but it is very breaky. This will break for people who use the existing action names, but I do agree that this redux-style action creators are preferable for those who aren't using flow. So I'm curious if anybody else feels strongly about this. |
Glad you support the change! I'm certainly aware this is breaky. I figure that given this has only been published for ~5 days and it's technically a beta release ( One thought: This library only consumes the actions in |
@ericvicenti - Just pushed a commit to prevent most of the breakage. So now:
The only thing this doesn't handle is a case where a user has a custom router with a custom |
c2df2b6
to
5abb954
Compare
Thanks for adding the informative warning, thats an excellent approach! Have you run flow on these changes? I know there are a bunch of existing flow issues, but I want to make sure this doesn't introduce more issues. |
There were 110 flow errors on master, 107 on this branch. I also confirmed the playground builds both worked fine but couldn't get the web running locally. The contributing docs refer to a 'prod' npm task that doesn't seem to exist. |
docs/api/routers/Routers.md
Outdated
if ( | ||
state && | ||
action.type === 'Back' && | ||
action.type === actions.BACK && |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
docs/api/routers/Routers.md
Outdated
|
||
```js | ||
|
||
import { actions } from 'react-navigation' |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
```javascript | ||
type BackAction = {type: 'Back'}; | ||
type URIAction = {type: 'URI', uri: string}; | ||
type BackAction = {type: 'navigation/BACK'}; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Ok, I think this is pretty much ready to land. @satya164, I agree about the capitalization. Want to clean that up and then ship this thing? |
@ericvicenti Sounds good. If @jacrbo doesn't manage to do it sometime, I can take it up :) |
@ericvicenti @satya164 - Currently the constants are all caps ( NavigationActions.Back === 'Navigation/Back'
NavigationActions.back() === { type: 'Navigation/Back' }
NavigationActions.SetParams === 'Navigation/SetParams'
NavigationActions.setParams() === { type: 'Navigation/SetParams' } Two points in favor of ALL_CAPS_SNAKE_CASE:
I'd be in favor of: NavigationActions.BACK === 'Navigation/BACK'
NavigationActions.back() === { type: 'Navigation/BACK' }
NavigationActions.SET_PARAMS === 'Navigation/SET_PARAMS'
NavigationActions.setParams() === { type: 'Navigation/SET_PARAMS' } ... but ultimately defer to you guys. Let me know what you think and I'll update the PR real quick. |
I'm fine with that too 👍 |
NativeModules, | ||
} from 'react-native'; | ||
import { | ||
actions, |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
2ee8eeb
to
7296fc4
Compare
I pushed up a commit but missed a few imports. Just fixed and force-pushed so I think what's up there should be good to go 👍 |
LGTM. @ericvicenti should I merge? |
First I just to want to say thanks for publishing this library! It feels really well thought-out and it's been easy to use.
The way redux actions are currently implemented in the codebase is brittle and error prone and doesn't follow the "best practices" espoused by the redux community and other redux-related packages. Namely:
{ type, payload }
) instead of using action creators (http://redux.js.org/docs/basics/Actions.html#action-creators)This PR addresses all of those issues. This library now exports the action type constants and action creators for each type and uses a
'navigation/'
namespace for the types to avoid collisions.NOTE: I just noticed the "common navigation" spec - cool idea! I still think these actions should be namespaced though and I think the
navigation
is pretty general.Test plan (required)
All the existing tests are still passing including new ones for the actions and action creators.
Code formatting
I followed the coding patterns within the codebase.