-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathglobal.js
More file actions
38 lines (33 loc) · 795 Bytes
/
global.js
File metadata and controls
38 lines (33 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var React = require('react');
var Global = React.createClass({
statics: {
get: function(name) {
if(typeof global !== 'undefined') {
return global[name];
} else if(typeof window !== 'undefined') {
return window[name]
} else {
return null;
}
}
},
shouldComponentUpdate: function() {
return false;
},
getScript: function() {
var script = '';
for (var key in this.props.values || {}) {
script += 'var ' + key + '=' + JSON.stringify(this.props.values[key]) + ';';
}
return script;
},
render: function() {
return React.createElement("script", {
type: "text/javascript",
dangerouslySetInnerHTML: {
__html: this.getScript()
}
});
}
});
module.exports = Global;