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

React Native Compatibility #102

Closed
jacobdfriedmann opened this issue Nov 30, 2015 · 6 comments
Closed

React Native Compatibility #102

jacobdfriedmann opened this issue Nov 30, 2015 · 6 comments

Comments

@jacobdfriedmann
Copy link
Contributor

Was playing with react native recently and attempted to use fluxthis because I like it. There are only a couple things (one important one) that would need to be changed in order to make it compatible. I even think the APIActionCreators will work because react-native polyfills xhr. However, ActionCreator pulls in react/lib/ReactPropTypes for payloadType validation. This obviously won't work in a react native project which would need to require something like require('react-native').PropTypes instead.

Not sure if there is a good way (or a convention) to have this dual peer dependency on react OR react-native, but it seems like there should be an easy way to achieve this. Just thought I'd open it up to conversation.

@jhorwit2
Copy link
Contributor

jhorwit2 commented Dec 1, 2015

I think the only solution would be to publish react-native specific versions along with our normal releases.

@AlanFoster
Copy link
Contributor

Slightly crazy suggestion -

Could we make use of peer dependencies here?

ie, create a new npm module fluxthis-prop-types for wrapping PropTypes, release two specific branch versions for react-native and react-dom, then specify fluxthis-prop-types as a peer dependency, defaulting to the react-dom branch version. If a developer wants to change this to use react-native proptypes, they will specify in their package.json that they want the react-native wrapper branch instead

@jmrog
Copy link
Contributor

jmrog commented Dec 21, 2015

Looking quickly through the source, I think @jacobdfriedmann is right that the dependency on react/lib/ReactPropTypes is the main issue. FluxThis only uses that for payload validation, I think (and only in dev environments), so I think it's really worth considering making that an optional dependency. It might even be as simple as putting the relevant require in a try-catch block (maybe first trying to require from react, then trying to require from react-native, and then giving up), making the validation parts in ActionCreator conditional on the presence of PropTypes, and possibly issuing a warning message to the user if no supplier of PropTypes is found.

@jmrog
Copy link
Contributor

jmrog commented Dec 23, 2015

I finally got a chance do some playing around with this tonight. @jacobdfriedmann, do you recall what the original problem was when you created this issue? I ask because I was actually able to get FluxThis working with React Native without any real tinkering at all. Things I tested: APIActionCreator with a request to a NodeJS endpoint that I quickly whipped up, plain old ActionCreator, and ImmutableStore. They all essentially "just worked" (even the validation of payloadTypes; see the second screenshot below).

One possible caveat is that I required the pre-built version of FluxThis; not sure how things would go with the uncompiled version.

screen shot 2015-12-22 at 8 55 57 pm

screen shot 2015-12-22 at 8 57 21 pm

EDIT to add: the validation failure in the second screenshot is right, even though the payloadType is string in the first screenshot; I temporarily changed it to number to check that it would fail.

@jacobdfriedmann
Copy link
Contributor Author

You're right...this isn't a problem if you use the prebuilt version, which comes packaged with the PropTypes module. I was requiring the source files. I guess there is no real need for me to do that. I'll close this.

@jmrog
Copy link
Contributor

jmrog commented Dec 31, 2015

This is also worth noting. It sounds like you might be able to require the source files without issue very soon. facebook/react-native#2985

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants