react-i13n
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -13,3 +13,2 @@ /** | ||
var DEFAULT_HANDLER_TIMEOUT = 1000; | ||
var GLOBAL_OBJECT = 'client' === ENVIRONMENT ? window : global; | ||
var ENVIRONMENT = typeof window !== 'undefined' ? 'client' : 'server'; | ||
@@ -39,3 +38,2 @@ | ||
this._i13nNodeClass = 'function' === typeof options.i13nNodeClass ? options.i13nNodeClass : I13nNode; | ||
this._plugins = {}; | ||
@@ -47,5 +45,2 @@ this._eventsQueues = {}; | ||
this._scrollableContainerId = options.scrollableContainerId || undefined; | ||
// set itself to the global object so that we can get it anywhere by the static function getInstance | ||
GLOBAL_OBJECT.reactI13n = this; | ||
}; | ||
@@ -60,3 +55,7 @@ | ||
ReactI13n.getInstance = function getInstance() { | ||
return GLOBAL_OBJECT.reactI13n; | ||
if ('client' === ENVIRONMENT) { | ||
return window._reactI13nInstance; | ||
} else if ('production' !== process.env.NODE_ENV) { | ||
console.warn('ReactI13n instance is not avaialble on server side with ReactI13n.getInstance, ' + 'please use this.props.i13n or this.context.i13n to access ReactI13n utils'); | ||
} | ||
}; | ||
@@ -70,7 +69,7 @@ | ||
var I13nNodeClass = this.getI13nNodeClass(); | ||
GLOBAL_OBJECT.rootI13nNode = new I13nNodeClass(null, this._rootModelData, false); | ||
this._rootI13nNode = new I13nNodeClass(null, this._rootModelData, false); | ||
if ('client' === ENVIRONMENT) { | ||
GLOBAL_OBJECT.rootI13nNode.setDOMNode(document.body); | ||
this._rootI13nNode.setDOMNode(document.body); | ||
} | ||
return GLOBAL_OBJECT.rootI13nNode; | ||
return this._rootI13nNode; | ||
}; | ||
@@ -199,3 +198,3 @@ | ||
ReactI13n.prototype.getRootI13nNode = function getRootI13nNode() { | ||
return GLOBAL_OBJECT.rootI13nNode; | ||
return this._rootI13nNode; | ||
}; | ||
@@ -202,0 +201,0 @@ |
@@ -17,2 +17,3 @@ /** | ||
var ReactI13n = require('../libs/ReactI13n'); | ||
var I13nNode = require('../libs/I13nNode'); | ||
var ViewportMixin = require('./viewport/ViewportMixin'); | ||
@@ -141,5 +142,2 @@ require('setimmediate'); | ||
componentWillMount: function componentWillMount() { | ||
if (!this._getReactI13n()) { | ||
return; | ||
} | ||
clearTimeout(pageInitViewportDetectionTimeout); | ||
@@ -371,6 +369,7 @@ this._createI13nNode(); | ||
var self = this; | ||
var I13nNode = self._getReactI13n().getI13nNodeClass(); | ||
var parentI13nNode = self._getParentI13nNode(); | ||
var reactI13n = self._getReactI13n(); | ||
var I13nNodeClass = reactI13n && reactI13n.getI13nNodeClass() || I13nNode; | ||
// TODO @kaesonho remove BC for model | ||
self._i13nNode = new I13nNode(parentI13nNode, self.props.i13nModel || self.props.model, self.isLeafNode(), self._getReactI13n().isViewportEnabled()); | ||
self._i13nNode = new I13nNodeClass(parentI13nNode, self.props.i13nModel || self.props.model, self.isLeafNode(), reactI13n && reactI13n.isViewportEnabled()); | ||
}, | ||
@@ -377,0 +376,0 @@ |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var ReactI13n = require('../libs/ReactI13n'); | ||
var IS_CLIENT = typeof window !== 'undefined'; | ||
@@ -18,3 +19,4 @@ /** | ||
getI13nNode: React.PropTypes.func, | ||
parentI13nNode: React.PropTypes.object | ||
parentI13nNode: React.PropTypes.object, | ||
_reactI13nInstance: React.PropTypes.object | ||
}) | ||
@@ -27,3 +29,4 @@ }, | ||
getI13nNode: React.PropTypes.func, | ||
parentI13nNode: React.PropTypes.object | ||
parentI13nNode: React.PropTypes.object, | ||
_reactI13nInstance: React.PropTypes.object | ||
}) | ||
@@ -41,3 +44,4 @@ }, | ||
getI13nNode: this.getI13nNode, | ||
parentI13nNode: this._i13nNode | ||
parentI13nNode: this._i13nNode, | ||
_reactI13nInstance: this._getReactI13n() | ||
} | ||
@@ -57,2 +61,3 @@ }; | ||
var reactI13nInstance = this._getReactI13n(); | ||
var errorMessage = ''; | ||
payload = payload || {}; | ||
@@ -63,2 +68,10 @@ payload.i13nNode = payload.i13nNode || this.getI13nNode(); | ||
} else { | ||
if ('production' !== process.env.NODE_ENV) { | ||
errorMessage = 'ReactI13n instance is not found, ' + 'please make sure you have setupI13n on the root component. '; | ||
if (!IS_CLIENT) { | ||
errorMessage += 'On server side, ' + 'you can only execute the i13n event on the components under setupI13n, ' + 'please make sure you are calling executeI13nEvent correctly'; | ||
} | ||
console && console.warn && console.warn(errorMessage); | ||
console && console.trace && console.trace(); | ||
} | ||
callback && callback(); | ||
@@ -74,5 +87,2 @@ } | ||
getI13nNode: function getI13nNode() { | ||
if (!this._getReactI13n()) { | ||
return; | ||
} | ||
return this._i13nNode || this._getParentI13nNode(); | ||
@@ -88,3 +98,7 @@ }, | ||
_getReactI13n: function _getReactI13n() { | ||
return ReactI13n.getInstance(); | ||
var globalReactI13n; | ||
if (IS_CLIENT) { | ||
globalReactI13n = window._reactI13nInstance; | ||
} | ||
return this._reactI13nInstance || this.context && this.context.i13n && this.context.i13n._reactI13nInstance || globalReactI13n; | ||
}, | ||
@@ -99,5 +113,5 @@ | ||
_getParentI13nNode: function _getParentI13nNode() { | ||
// https://twitter.com/andreypopp/status/578974316483608576, get the context from parent context | ||
var reactI13n = this._getReactI13n(); | ||
var context = this.context; | ||
return context && context.i13n && context.i13n.parentI13nNode || this._getReactI13n().getRootI13nNode(); | ||
return context && context.i13n && context.i13n.parentI13nNode || reactI13n && reactI13n.getRootI13nNode(); | ||
} | ||
@@ -104,0 +118,0 @@ }; |
@@ -10,2 +10,3 @@ /** | ||
var supportClassList = false; | ||
var uniqueId = 0; | ||
@@ -87,2 +88,5 @@ | ||
// check if browser support classList API | ||
supportClassList = 'classList' in container; | ||
self.modelItemsListener = []; | ||
@@ -159,5 +163,11 @@ | ||
container.style['z-index'] = '11'; | ||
if (supportClassList) { | ||
container.classList.add('active'); | ||
} | ||
} else { | ||
dashboard.style.display = 'none'; | ||
container.style['z-index'] = '10'; | ||
if (supportClassList) { | ||
container.classList.remove('active'); | ||
} | ||
} | ||
@@ -180,2 +190,6 @@ }); | ||
self.container = container; | ||
if (supportClassList) { | ||
document.documentElement.classList.add('i13n-debug-enabled'); | ||
} | ||
}; | ||
@@ -182,0 +196,0 @@ |
@@ -10,2 +10,3 @@ /** | ||
var I13nUtils = require('../mixins/I13nUtils'); | ||
var IS_CLIENT = typeof window !== 'undefined'; | ||
@@ -29,7 +30,2 @@ /** | ||
var reactI13n = new ReactI13n(options); | ||
plugins.forEach(function setPlugin(plugin) { | ||
reactI13n.plug(plugin); | ||
}); | ||
RootI13nComponent = React.createClass({ | ||
@@ -48,3 +44,12 @@ | ||
componentWillMount: function componentWillMount() { | ||
var reactI13n = ReactI13n.getInstance(); | ||
var reactI13n = new ReactI13n(options); | ||
this._reactI13nInstance = reactI13n; | ||
// we might have case to access reactI13n instance to execute event outside react components | ||
// assign reactI13n to window | ||
if (IS_CLIENT) { | ||
window._reactI13nInstance = reactI13n; | ||
} | ||
plugins.forEach(function setPlugin(plugin) { | ||
reactI13n.plug(plugin); | ||
}); | ||
reactI13n.createRootI13nNode(); | ||
@@ -57,3 +62,4 @@ }, | ||
executeEvent: this.executeI13nEvent, | ||
getI13nNode: this.getI13nNode | ||
getI13nNode: this.getI13nNode, | ||
reactI13nInstance: this._reactI13nInstance | ||
} | ||
@@ -60,0 +66,0 @@ }, this.props); |
{ | ||
"name": "react-i13n", | ||
"description": "React I13n provides a performant and scalable solution to application instrumentation.", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"main": "index.js", | ||
@@ -13,3 +13,3 @@ "repository": { | ||
"lint": "jshint", | ||
"test": "grunt cover" | ||
"test": "grunt unit && grunt cover" | ||
}, | ||
@@ -50,2 +50,3 @@ "dependencies": { | ||
"react-dom": "^15.0.0", | ||
"webpack": "^1.13.1", | ||
"xunit-file": "~0.0.7" | ||
@@ -52,0 +53,0 @@ }, |
@@ -89,3 +89,2 @@ # react-i13n | ||
## I13n Tree | ||
@@ -92,0 +91,0 @@ ![I13n Tree](https://cloud.githubusercontent.com/assets/3829183/7980892/0b38eb70-0a60-11e5-8cc2-712ec42089fc.png) |
79605
1851
29
156
6