1
1
/* global FastBoot */
2
+ import { set } from '@ember/object' ;
2
3
import { getOwner } from '@ember/application' ;
3
4
import { computed , get } from '@ember/object' ;
4
5
import { readOnly } from '@ember/object/computed' ;
@@ -20,58 +21,72 @@ const RequestObject = EObject.extend({
20
21
this . queryParams = request . queryParams ;
21
22
this . path = request . path ;
22
23
this . protocol = request . protocol ;
23
- this . _host = function ( ) {
24
+ this . _host = function ( ) {
24
25
return request . host ( ) ;
25
26
} ;
26
27
} ,
27
28
28
- host : computed ( function ( ) {
29
+ host : computed ( function ( ) {
29
30
return this . _host ( ) ;
30
- } )
31
+ } ) ,
31
32
} ) ;
32
33
33
34
const Shoebox = EObject . extend ( {
34
35
put ( key , value ) {
35
- assert ( 'shoebox.put is only invoked from the FastBoot rendered application' , this . get ( 'fastboot.isFastBoot' ) ) ;
36
+ assert (
37
+ 'shoebox.put is only invoked from the FastBoot rendered application' ,
38
+ this . get ( 'fastboot.isFastBoot' )
39
+ ) ;
36
40
assert ( 'the provided key is a string' , typeof key === 'string' ) ;
37
41
38
42
let fastbootInfo = this . get ( 'fastboot._fastbootInfo' ) ;
39
- if ( ! fastbootInfo . shoebox ) { fastbootInfo . shoebox = { } ; }
43
+ if ( ! fastbootInfo . shoebox ) {
44
+ fastbootInfo . shoebox = { } ;
45
+ }
40
46
41
47
fastbootInfo . shoebox [ key ] = value ;
42
48
} ,
43
49
44
50
retrieve ( key ) {
45
51
if ( this . get ( 'fastboot.isFastBoot' ) ) {
46
52
let shoebox = this . get ( 'fastboot._fastbootInfo.shoebox' ) ;
47
- if ( ! shoebox ) { return ; }
53
+ if ( ! shoebox ) {
54
+ return ;
55
+ }
48
56
49
57
return shoebox [ key ] ;
50
58
}
51
59
52
60
let shoeboxItem = this . get ( key ) ;
53
- if ( shoeboxItem ) { return shoeboxItem ; }
61
+ if ( shoeboxItem ) {
62
+ return shoeboxItem ;
63
+ }
54
64
55
65
let el = document . querySelector ( `#shoebox-${ key } ` ) ;
56
- if ( ! el ) { return ; }
66
+ if ( ! el ) {
67
+ return ;
68
+ }
57
69
let valueString = el . textContent ;
58
- if ( ! valueString ) { return ; }
70
+ if ( ! valueString ) {
71
+ return ;
72
+ }
59
73
60
74
shoeboxItem = JSON . parse ( valueString ) ;
61
75
this . set ( key , shoeboxItem ) ;
62
76
63
77
return shoeboxItem ;
64
- }
78
+ } ,
65
79
} ) ;
66
80
67
81
const FastBootService = Service . extend ( {
68
82
isFastBoot : typeof FastBoot !== 'undefined' ,
69
83
70
- isFastboot : computed ( function ( ) {
84
+ isFastboot : computed ( function ( ) {
71
85
assert (
72
86
'The fastboot service does not have an `isFastboot` property. This is likely a typo. Please use `isFastBoot` instead.' ,
73
87
false
74
88
) ;
89
+ return ;
75
90
} ) ,
76
91
77
92
init ( ) {
@@ -84,13 +99,15 @@ const FastBootService = Service.extend({
84
99
response : readOnly ( '_fastbootInfo.response' ) ,
85
100
metadata : readOnly ( '_fastbootInfo.metadata' ) ,
86
101
87
- request : computed ( function ( ) {
102
+ request : computed ( '_fastbootInfo.request' , 'isFastBoot' , function ( ) {
88
103
if ( ! this . isFastBoot ) return null ;
89
- return RequestObject . create ( { request : get ( this , '_fastbootInfo.request' ) } ) ;
104
+ return RequestObject . create ( {
105
+ request : get ( this , '_fastbootInfo.request' ) ,
106
+ } ) ;
90
107
} ) ,
91
108
92
109
// this getter/setter pair is to avoid deprecation from [RFC - 680](https://github.com/emberjs/rfcs/pull/680)
93
- _fastbootInfo : computed ( {
110
+ _fastbootInfo : computed ( '__fastbootInfo' , {
94
111
get ( ) {
95
112
if ( this . __fastbootInfo ) {
96
113
return this . __fastbootInfo ;
@@ -99,15 +116,18 @@ const FastBootService = Service.extend({
99
116
return getOwner ( this ) . lookup ( 'info:-fastboot' ) ;
100
117
} ,
101
118
set ( _key , value ) {
102
- this . __fastbootInfo = value ;
119
+ set ( this , ' __fastbootInfo' , value ) ;
103
120
return value ;
104
- }
121
+ } ,
105
122
} ) ,
106
123
107
124
deferRendering ( promise ) {
108
- assert ( 'deferRendering requires a promise or thennable object' , typeof promise . then === 'function' ) ;
125
+ assert (
126
+ 'deferRendering requires a promise or thennable object' ,
127
+ typeof promise . then === 'function'
128
+ ) ;
109
129
this . _fastbootInfo . deferRendering ( promise ) ;
110
- }
130
+ } ,
111
131
} ) ;
112
132
113
133
export default FastBootService ;
0 commit comments