@@ -17,12 +17,14 @@ var Spinner = React.createClass({
17
17
var App = React . createClass ( {
18
18
mixins : [ Navigation ] ,
19
19
20
+ getDefaultProps ( ) {
21
+ return { contacts : [ ] } ;
22
+ } ,
23
+
20
24
statics : {
21
25
loadProps ( params , cb ) {
22
26
loadContacts ( cb ) ;
23
- } ,
24
-
25
- Loader : Spinner
27
+ }
26
28
} ,
27
29
28
30
handleSubmit ( event ) {
@@ -31,22 +33,28 @@ var App = React.createClass({
31
33
first : event . target . elements [ 0 ] . value ,
32
34
last : event . target . elements [ 1 ] . value
33
35
} , ( err , data ) => {
34
- this . props . onPropsDidChange ( ) ;
36
+ this . props . reloadAsyncProps ( ) ;
35
37
this . transitionTo ( `/contact/${ data . contact . id } ` ) ;
36
38
} ) ;
37
39
event . target . reset ( ) ;
38
40
event . target . elements [ 0 ] . focus ( ) ;
39
41
} ,
40
42
41
43
render ( ) {
44
+ // super smooth user feedback
45
+ var appStyle = {
46
+ transition : this . props . loading ? 'opacity 500ms ease 250ms' : 'opacity 150ms' ,
47
+ opacity : this . props . loading ? 0.5 : 1
48
+ } ;
49
+
42
50
return (
43
- < div className = "App" >
51
+ < div className = "App" style = { appStyle } >
44
52
< form onSubmit = { this . handleSubmit } >
45
53
< input placeholder = "First name" /> < input placeholder = "Last name" /> { ' ' }
46
54
< button type = "submit" > submit</ button >
47
55
</ form >
48
56
< div style = { { display : 'flex' } } >
49
- < ul style = { { opacity : this . props . propsAreLoadingLong ? 0.5 : 1 , padding : 20 } } >
57
+ < ul style = { { opacity : this . props . loadingAsyncProps ? 0.5 : 1 , padding : 20 } } >
50
58
{ this . props . contacts . map ( ( contact , i ) => (
51
59
< li key = { contact . id } >
52
60
< Link to = { `/contact/${ contact . id } ` } > { contact . first } { contact . last } </ Link >
@@ -64,29 +72,24 @@ var App = React.createClass({
64
72
65
73
var Contact = React . createClass ( {
66
74
75
+ getDefaultProps ( ) {
76
+ return { contact : { } } ;
77
+ } ,
78
+
67
79
statics : {
68
80
loadProps ( params , cb ) {
69
- //console.log('Contact loadProps');
70
81
loadContact ( params . id , cb ) ;
71
- } ,
72
-
73
- Loader : Spinner
74
- } ,
75
-
76
- getInitialState ( ) {
77
- return {
78
- longLoad : false
79
- } ;
82
+ }
80
83
} ,
81
84
82
85
render ( ) {
83
86
var { contact } = this . props ;
84
87
85
88
return (
86
- < div style = { { opacity : this . props . propsAreLoadingLong ? 0.5 : 1 } } >
89
+ < div style = { { opacity : this . props . loadingAsyncProps ? 0.5 : 1 } } >
87
90
< p > < Link to = "/" > Back</ Link > </ p >
88
91
< h1 > { contact . first } { contact . last } </ h1 >
89
- < img key = { contact . avatar } src = { contact . avatar } height = "200" />
92
+ < p > < img key = { contact . avatar } src = { contact . avatar } height = "200" /> </ p >
90
93
</ div >
91
94
) ;
92
95
}
@@ -103,10 +106,12 @@ var Index = React.createClass({
103
106
} ) ;
104
107
105
108
React . render ( (
106
- < Router history = { new HashHistory } createElement = { AsyncProps . createElement } >
107
- < Route component = { App } >
108
- < Route path = "/" component = { Index } />
109
- < Route path = "contact/:id" component = { Contact } />
109
+ < Router history = { new HashHistory ( ) } createElement = { AsyncProps . createElement } >
110
+ < Route component = { AsyncProps } renderInitialLoad = { ( ) => < Spinner /> } >
111
+ < Route component = { App } >
112
+ < Route path = "/" component = { Index } />
113
+ < Route path = "contact/:id" component = { Contact } />
114
+ </ Route >
110
115
</ Route >
111
116
</ Router >
112
117
) , document . getElementById ( 'example' ) ) ;
0 commit comments