Skip to content

Commit 60c8a76

Browse files
skevyfacebook-github-bot-7
authored andcommitted
React Native Compatibility
Summary: **This PR depends on an unreleased version of `fbjs`, so DO NOT MERGE.** When merged along with facebook/react-native#5084, facebook/fbjs#95, and whatever PR fixes facebook/react-native#4062 (which I will update this issue with when I push it), this fixes #26. The changes to Relay itself are super minor here: 1. Remove the reliance on ReactDOM. The only use of ReactDOM is `unstable_batchedupdates`. So to fix, I abstracted the reference to `unstable_batchedupdates` to it's own module, and then took advantage of the "react-native" `package.json` option, supported by the React Native packager, to load the correct version of this function given the execution context. 2. Removed `react-dom` from peerDependencies (but kept it in devDependencies, for use in tests), and also upgrade the `fbjs` dependency to a (yet unreleased) version that provides better compatibility with React Native. Closes #713 Reviewed By: yungsters Differential Revision: D2872129 fb-gh-sync-id: f6ba6d06cfdde8ad8cbb0c7cd9d645f44f65e437
1 parent 482ee7c commit 60c8a76

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var babelOpts = {
6464
_moduleMap: objectAssign({}, require('fbjs/module-map'), {
6565
'React': 'react',
6666
'ReactDOM': 'react-dom',
67+
'ReactNative': 'react-native',
6768
'StaticContainer.react': 'react-static-container',
6869
}),
6970
};

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
},
3030
"dependencies": {
3131
"babel-runtime": "5.8.24",
32-
"fbjs": "^0.5.1",
32+
"fbjs": "^0.7.0",
3333
"react-static-container": "^1.0.0-alpha.1"
3434
},
3535
"peerDependencies": {
3636
"babel-relay-plugin": "0.6.3",
37-
"react": "^0.14.0",
38-
"react-dom": "^0.14.0"
37+
"react": "^0.14.0"
3938
},
4039
"devDependencies": {
4140
"babel": "^5.8.25",
@@ -55,15 +54,15 @@
5554
"gulp-util": "^3.0.6",
5655
"jest-cli": "^0.8.1",
5756
"object-assign": "^3.0.0",
58-
"react": "^0.14.0-rc",
59-
"react-dom": "^0.14.0-rc",
57+
"react": "^0.14.0",
58+
"react-dom": "^0.14.0",
6059
"run-sequence": "^1.1.2",
6160
"webpack": "1.11.0",
6261
"webpack-stream": "^2.1.0"
6362
},
6463
"devEngines": {
65-
"node": "4.x",
66-
"npm": "2.x"
64+
"node": ">=4.x",
65+
"npm": ">=2.x"
6766
},
6867
"jest": {
6968
"rootDir": "",
@@ -73,6 +72,7 @@
7372
"persistModuleRegistryBetweenSpecs": true,
7473
"modulePathIgnorePatterns": [
7574
"<rootDir>/lib/",
75+
"<rootDir>/src/(.*).native.js",
7676
"<rootDir>/node_modules/(?!(fbjs/lib/|react/lib/|fbjs-scripts/jest))"
7777
],
7878
"preprocessorIgnorePatterns": [

src/.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.*/react-static-container/node_modules/.*
66

77
[include]
8-
../node_modules/fbjs/flow/include
8+
../node_modules/fbjs/lib
99
../node_modules/fbjs/node_modules/promise
1010
../node_modules/react
1111
../node_modules/react-static-container/lib

src/container/RelayContainer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const ErrorUtils = require('ErrorUtils');
1818
const GraphQLFragmentPointer = require('GraphQLFragmentPointer');
1919
const GraphQLStoreQueryResolver = require('GraphQLStoreQueryResolver');
2020
const React = require('React');
21-
const ReactDOM = require('ReactDOM');
2221
const RelayContainerComparators = require('RelayContainerComparators');
2322
const RelayContainerProxy = require('RelayContainerProxy');
2423
const RelayFragmentReference = require('RelayFragmentReference');
@@ -47,6 +46,7 @@ const forEachObject = require('forEachObject');
4746
const invariant = require('invariant');
4847
const nullthrows = require('nullthrows');
4948
const prepareRelayContainerProps = require('prepareRelayContainerProps');
49+
const relayUnstableBatchedUpdates = require('relayUnstableBatchedUpdates');
5050
const shallowEqual = require('shallowEqual');
5151
const warning = require('warning');
5252
const isReactComponent = require('isReactComponent');
@@ -80,7 +80,7 @@ var containerContextTypes = {
8080
var storeData = RelayStoreData.getDefaultInstance();
8181

8282
storeData.getChangeEmitter().injectBatchingStrategy(
83-
ReactDOM.unstable_batchedUpdates
83+
relayUnstableBatchedUpdates
8484
);
8585

8686
/**
@@ -286,7 +286,7 @@ function createContainerComponent(
286286
var mounted = this.mounted;
287287
if (mounted) {
288288
var updateProfiler = RelayProfiler.profile('RelayContainer.update');
289-
ReactDOM.unstable_batchedUpdates(() => {
289+
relayUnstableBatchedUpdates(() => {
290290
this.setState(partialState, () => {
291291
updateProfiler.stop();
292292
if (isComplete) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = require.requireActual('relayUnstableBatchedUpdates');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule relayUnstableBatchedUpdates
10+
* @flow
11+
* @typechecks
12+
*/
13+
14+
'use strict';
15+
16+
const ReactDOM = require('ReactDOM');
17+
18+
module.exports = ReactDOM.unstable_batchedUpdates;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule relayUnstableBatchedUpdates
10+
*/
11+
12+
'use strict';
13+
14+
const ReactNative = require('ReactNative');
15+
16+
module.exports = ReactNative.unstable_batchedUpdates;

0 commit comments

Comments
 (0)