Skip to content

Commit

Permalink
Make root instance provider injectable. Fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jan 1, 2015
1 parent c2121b6 commit 92ba675
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
8 changes: 8 additions & 0 deletions DefaultRootInstanceProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
getRootInstances: function () {
var ReactMount = require('react/lib/ReactMount');
return ReactMount._instancesByReactRootID || ReactMount._instancesByContainerID;
}
};
7 changes: 7 additions & 0 deletions Injection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var RootInstanceProvider = require('./RootInstanceProvider');

module.exports = {
RootInstanceProvider: RootInstanceProvider.injection
};
21 changes: 21 additions & 0 deletions RootInstanceProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var DefaultRootInstanceProvider = require('./DefaultRootInstanceProvider');

var injectedProvider = null;

var RootInstanceProvider = {
injection: {
injectProvider: function (provider) {
injectedProvider = provider;
}
},

getRootInstances: function () {
return injectedProvider.getRootInstances();
}
};

RootInstanceProvider.injection.injectProvider(DefaultRootInstanceProvider);

module.exports = RootInstanceProvider;
8 changes: 0 additions & 8 deletions getRootInstances.js

This file was deleted.

8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ module.exports = function (source, map) {
'/* REACT HOT LOADER */',
'if (module.hot) {',
'(function () {',
'var reactHotApi = require(' + JSON.stringify(require.resolve('react-hot-api')) + '),',
' getRootInstances = require(' + JSON.stringify(require.resolve('./getRootInstances')) + ');',
'var ReactHotAPI = require(' + JSON.stringify(require.resolve('react-hot-api')) + '),',
' RootInstanceProvider = require(' + JSON.stringify(require.resolve('./RootInstanceProvider')) + ');',
'',
'if (typeof reactHotApi === "function" && typeof getRootInstances === "function") {',
'module.makeHot = module.hot.data ? module.hot.data.makeHot : reactHotApi(getRootInstances);',
'if (typeof ReactHotAPI === "function" && typeof RootInstanceProvider === "object") {',
'module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(RootInstanceProvider.getRootInstances);',
'}',
'})();',
'}'
Expand Down

0 comments on commit 92ba675

Please sign in to comment.