-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
59 lines (44 loc) · 1.29 KB
/
index.jsx
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
var di = require('di');
var i = 0;
var HTTP = function(){
return function(){
this.i = i++;
}
}
di.annotate(HTTP, new di.Provide(HTTP));
var MyComponentViewModel = function($HTTP){
return function(){
this.http = new $HTTP();
}
}
di.annotate(MyComponentViewModel, new di.Provide(MyComponentViewModel));
di.annotate(MyComponentViewModel, new di.Inject(HTTP));
var ChildComponent = function($ViewModel){
return React.createClass({
render: function() {
this.viewModel = this.viewModel || new $ViewModel();
return (
<div>Child {this.viewModel.http.i}</div>
);
}
});
}
di.annotate(ChildComponent, new di.Provide(ChildComponent));
di.annotate(ChildComponent, new di.Inject(MyComponentViewModel));
var RootComponent = function(Child){
return React.createClass({
render: function(){
return (
<div>
<Child />
<Child />
</div>
);
}
})
}
di.annotate(RootComponent, new di.Provide(RootComponent));
di.annotate(RootComponent, new di.Inject(ChildComponent));
var injector = new di.Injector();
var Root = injector.get(RootComponent);
React.render(<Root/>, document.getElementById('content'));