@@ -35,6 +35,19 @@ export default Ember.Route.extend({
35
35
return result ;
36
36
} ;
37
37
38
+ const fetchCrateDocumentation = ( ) => {
39
+ if ( ! crate . get ( 'documentation' ) ) {
40
+ let crateName = crate . get ( 'name' ) ;
41
+ let crateVersion = params . version_num ;
42
+ ajax ( `https://docs.rs/crate/${ crateName } /${ crateVersion } /builds.json` )
43
+ . then ( ( r ) => {
44
+ if ( r . length > 0 && r [ 0 ] . build_status === true ) {
45
+ crate . set ( 'documentation' , `https://docs.rs/${ crateName } /${ crateVersion } /` ) ;
46
+ }
47
+ } ) ;
48
+ }
49
+ } ;
50
+
38
51
// Fallback to the crate's last stable version
39
52
// If `max_version` is `0.0.0` then all versions have been yanked
40
53
if ( ! requestedVersion && maxVersion !== '0.0.0' ) {
@@ -52,10 +65,13 @@ export default Ember.Route.extend({
52
65
} else {
53
66
params . version_num = latestStableVersion . get ( 'num' ) ;
54
67
}
55
- } ) ;
68
+ } ) . then ( fetchCrateDocumentation ) ;
56
69
} else {
57
70
params . version_num = maxVersion ;
71
+ fetchCrateDocumentation ( ) ;
58
72
}
73
+ } else {
74
+ fetchCrateDocumentation ( ) ;
59
75
}
60
76
61
77
controller . set ( 'crate' , crate ) ;
@@ -68,17 +84,6 @@ export default Ember.Route.extend({
68
84
. finally ( ( ) => controller . set ( 'fetchingFollowing' , false ) ) ;
69
85
}
70
86
71
- if ( ! crate . get ( 'documentation' ) ) {
72
- let crateName = crate . get ( 'name' ) ;
73
- let crateVersion = params . version_num ;
74
- ajax ( `https://docs.rs/crate/${ crateName } /${ crateVersion } /builds.json` )
75
- . then ( ( r ) => {
76
- if ( r . length > 0 && r [ 0 ] . build_status === true ) {
77
- crate . set ( 'documentation' , `https://docs.rs/${ crateName } /${ crateVersion } /` ) ;
78
- }
79
- } ) ;
80
- }
81
-
82
87
// Find version model
83
88
return crate . get ( 'versions' )
84
89
. then ( versions => {
0 commit comments