-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
73 lines (55 loc) · 1.33 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Module dependencies
*/
var React = require('react');
var assign = require('object-assign');
var createClass = React.createClass;
var el = React.createElement;
/**
* Expose the PoeApp
*/
exports = module.exports = PoeApp;
exports['default'] = PoeApp;
/**
* Create a PoeApp
*
* @param {Object} context
*/
function PoeApp(context) {
if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
window.hyperFormat = context.format;
window.hyperStore = context.store;
}
var routeOpts = context.router || {};
delete context.router;
var Routes = routeOpts.routes;
if (!Routes) throw new Error('Missing routes');
delete routeOpts.routes;
var root = el(Routes, assign({
format: context.format
}, routeOpts));
return el(withContext(context, root));
}
exports.React = React;
function withContext(context, child) {
return createClass({
displayName: 'PoeApp',
childContextTypes: Object.keys(context).reduce(function(acc, key) {
acc[key] = React.PropTypes.any;
return acc;
}, {}),
getChildContext: function() {
return context;
},
render: function() {
return child;
}
});
}
/**
* Expose React to the window
*/
if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
window.React = React;
}
exports.__esModule = true