@@ -10,7 +10,6 @@ var debug = debugLib('ReactI13n');
10
10
var EventsQueue = require ( './EventsQueue' ) ;
11
11
var I13nNode = require ( './I13nNode' ) ;
12
12
var DEFAULT_HANDLER_TIMEOUT = 1000 ;
13
- var GLOBAL_OBJECT = ( 'client' === ENVIRONMENT ) ? window : global ;
14
13
var ENVIRONMENT = ( typeof window !== 'undefined' ) ? 'client' : 'server' ;
15
14
16
15
// export the debug lib in client side
@@ -26,6 +25,7 @@ if ('client' === ENVIRONMENT) {
26
25
* @param {Object } options.rootModelData model data of root i13n node
27
26
* @param {Object } options.i13nNodeClass the i13nNode class, you can inherit it with your own functionalities
28
27
* @param {String } options.scrollableContainerId id of the scrollable element that your components
28
+ * @param {String } options.context context object
29
29
* reside within. Normally, you won't need to provide a value for this. This is only to
30
30
* support viewport checking when your components are contained within a scrollable element.
31
31
* Currently, only elements that fill the viewport are supported.
@@ -42,19 +42,21 @@ var ReactI13n = function ReactI13n (options) {
42
42
this . _rootModelData = options . rootModelData || { } ;
43
43
this . _handlerTimeout = options . handlerTimeout || DEFAULT_HANDLER_TIMEOUT ;
44
44
this . _scrollableContainerId = options . scrollableContainerId || undefined ;
45
+ this . _context = options . context ;
45
46
46
47
// set itself to the global object so that we can get it anywhere by the static function getInstance
47
- GLOBAL_OBJECT . reactI13n = this ;
48
+ this . _context . reactI13n = this ;
48
49
} ;
49
50
50
51
/**
51
52
* Get ReactI13n Instance
52
53
* @method getInstance
54
+ * @param {Object } context context object
53
55
* @return the ReactI13n instance
54
56
* @static
55
57
*/
56
- ReactI13n . getInstance = function getInstance ( ) {
57
- return GLOBAL_OBJECT . reactI13n ;
58
+ ReactI13n . getInstance = function getInstance ( context ) {
59
+ return context . reactI13n ; ;
58
60
} ;
59
61
60
62
/**
@@ -63,11 +65,14 @@ ReactI13n.getInstance = function getInstance () {
63
65
*/
64
66
ReactI13n . prototype . createRootI13nNode = function createRootI13nNode ( ) {
65
67
var I13nNodeClass = this . getI13nNodeClass ( ) ;
66
- GLOBAL_OBJECT . rootI13nNode = new I13nNodeClass ( null , this . _rootModelData , false ) ;
68
+ if ( this . _context . rootI13nNode ) {
69
+ return this . _context . rootI13nNode ;
70
+ }
71
+ this . _context . rootI13nNode = new I13nNodeClass ( null , this . _rootModelData , false ) ;
67
72
if ( 'client' === ENVIRONMENT ) {
68
- GLOBAL_OBJECT . rootI13nNode . setDOMNode ( document . body ) ;
73
+ this . _context . rootI13nNode . setDOMNode ( document . body ) ;
69
74
}
70
- return GLOBAL_OBJECT . rootI13nNode ;
75
+ return this . _context . rootI13nNode ;
71
76
} ;
72
77
73
78
/**
@@ -191,7 +196,7 @@ ReactI13n.prototype.getScrollableContainerDOMNode = function getScrollableContai
191
196
* @return {Object } root react i13n node
192
197
*/
193
198
ReactI13n . prototype . getRootI13nNode = function getRootI13nNode ( ) {
194
- return GLOBAL_OBJECT . rootI13nNode ;
199
+ return this . _context . rootI13nNode ;
195
200
} ;
196
201
197
202
/**
0 commit comments