From 9c57bc587d39eea93c7a159937a309f4bdfd2407 Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Thu, 24 Sep 2015 16:36:32 -0700 Subject: [PATCH 1/6] Attempt to load react-native when loading react fails --- lib/component.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/component.js b/lib/component.js index b7c7ce4..a265f35 100644 --- a/lib/component.js +++ b/lib/component.js @@ -32,7 +32,13 @@ if (typeof define === 'function' && define.amd) { define(['react', 'backbone', 'underscore'], factory); } else if (typeof module !== 'undefined' && module.exports) { - module.exports = factory(require('react'), require('backbone'), require('underscore')); + var react = null; + try { + react = require('react'); + } catch (error) { + react = require('React'); // React Native + } + module.exports = factory(react, require('backbone'), require('underscore')); } else { factory(root.React, root.Backbone, root._); } From a05dae5df1194f36e3ebf1be53ea2d6ee22ed1cc Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Thu, 24 Sep 2015 16:42:20 -0700 Subject: [PATCH 2/6] Only use DOM access methods outside of react-native --- lib/component.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/component.js b/lib/component.js index a265f35..5bc6cf8 100644 --- a/lib/component.js +++ b/lib/component.js @@ -33,16 +33,18 @@ define(['react', 'backbone', 'underscore'], factory); } else if (typeof module !== 'undefined' && module.exports) { var react = null; + var isReactNative = false; try { react = require('react'); } catch (error) { react = require('React'); // React Native + isReactNative = true; } - module.exports = factory(react, require('backbone'), require('underscore')); + module.exports = factory(isReactNative, react, require('backbone'), require('underscore')); } else { factory(root.React, root.Backbone, root._); } -}(this, function (React, Backbone, _) { +}(this, function (isReactNative, React, Backbone, _) { 'use strict'; if (!Backbone.React) { Backbone.React = {}; @@ -76,11 +78,15 @@ }, // Sets `this.el` and `this.$el` when the component mounts. componentDidMount: function () { - this.setElement(React.findDOMNode(this)); + if (isReactNative === false) { + this.setElement(React.findDOMNode(this)); + } }, // Sets `this.el` and `this.$el` when the component updates. componentDidUpdate: function () { - this.setElement(React.findDOMNode(this)); + if (isReactNative === false) { + this.setElement(React.findDOMNode(this)); + } }, // When the component gets the initial state, instance a `Wrapper` to take // care of models and collections binding with `this.state`. From 26443b4f81576055d1f63068b50d967fee2e94f0 Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Fri, 6 Nov 2015 01:06:41 -0800 Subject: [PATCH 3/6] Require react-native instead of react first React Native 0.14.0's packager fails when a require() doesn't resolve (rather than dispatching a caught exception). --- lib/component.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/component.js b/lib/component.js index 5bc6cf8..881bc89 100644 --- a/lib/component.js +++ b/lib/component.js @@ -32,14 +32,8 @@ if (typeof define === 'function' && define.amd) { define(['react', 'backbone', 'underscore'], factory); } else if (typeof module !== 'undefined' && module.exports) { - var react = null; - var isReactNative = false; - try { - react = require('react'); - } catch (error) { - react = require('React'); // React Native - isReactNative = true; - } + react = require('React'); // React Native + isReactNative = true; module.exports = factory(isReactNative, react, require('backbone'), require('underscore')); } else { factory(root.React, root.Backbone, root._); From 5de07f77983b24d4ecca72233c4cbaa9108b4f82 Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Fri, 6 Nov 2015 01:10:34 -0800 Subject: [PATCH 4/6] Add peer dependency for react-native@0.14.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d68051..9c00928 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "peerDependencies": { "backbone": "^1.2.3", - "react": "^0.13.3" + "react-native": "^0.14.0" }, "dependencies": { "underscore": "^1.8.3" From 4356d55f0162c9c1558cef26585e883e232c2fb2 Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Fri, 6 Nov 2015 01:14:58 -0800 Subject: [PATCH 5/6] Use require('react-native') when requiring 0.14.0+ --- lib/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/component.js b/lib/component.js index 881bc89..8db794b 100644 --- a/lib/component.js +++ b/lib/component.js @@ -32,7 +32,7 @@ if (typeof define === 'function' && define.amd) { define(['react', 'backbone', 'underscore'], factory); } else if (typeof module !== 'undefined' && module.exports) { - react = require('React'); // React Native + react = require('react-native'); // React Native isReactNative = true; module.exports = factory(isReactNative, react, require('backbone'), require('underscore')); } else { From bbc2f1c8e039c48fd6c7ddc7dc94d858dea31438 Mon Sep 17 00:00:00 2001 From: Shaheen Gandhi Date: Tue, 19 Jan 2016 23:02:42 -0800 Subject: [PATCH 6/6] Specify react native peerDependency better --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c00928..a16feeb 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "peerDependencies": { "backbone": "^1.2.3", - "react-native": "^0.14.0" + "react-native": ">=0.14.0" }, "dependencies": { "underscore": "^1.8.3"