22import Ember from "ember" ;
33
44const { deprecate, computed, get } = Ember ;
5- const { alias , deprecatingAlias, readOnly } = computed ;
5+ const { deprecatingAlias, readOnly } = computed ;
66
77const RequestObject = Ember . Object . extend ( {
88 init ( ) {
@@ -18,18 +18,59 @@ const RequestObject = Ember.Object.extend({
1818 this . protocol = request . protocol ;
1919 this . _host = function ( ) {
2020 return request . host ( ) ;
21- }
21+ } ;
2222 } ,
2323
2424 host : computed ( function ( ) {
2525 return this . _host ( ) ;
2626 } )
2727} ) ;
2828
29+ const Shoebox = Ember . Object . extend ( {
30+ put ( key , value ) {
31+ Ember . assert ( 'shoebox.put is only invoked from the FastBoot rendered application' , this . get ( 'fastboot.isFastBoot' ) ) ;
32+ Ember . assert ( 'the provided key is a string' , typeof key === 'string' ) ;
33+
34+ let fastbootInfo = this . get ( 'fastboot._fastbootInfo' ) ;
35+ if ( ! fastbootInfo . shoebox ) { fastbootInfo . shoebox = { } ; }
36+
37+ fastbootInfo . shoebox [ key ] = value ;
38+ } ,
39+
40+ retrieve ( key ) {
41+ if ( this . get ( 'fastboot.isFastBoot' ) ) {
42+ let shoebox = this . get ( 'fastboot._fastbootInfo.shoebox' ) ;
43+ if ( ! shoebox ) { return ; }
44+
45+ return shoebox [ key ] ;
46+ }
47+
48+ let shoeboxItem = this . get ( key ) ;
49+ if ( shoeboxItem ) { return shoeboxItem ; }
50+
51+ let $el = Ember . $ ( `#shoebox-${ key } ` ) ;
52+ if ( ! $el . length ) { return ; }
53+ let valueString = $el . text ( ) ;
54+ if ( ! valueString ) { return ; }
55+
56+ shoeboxItem = JSON . parse ( valueString ) ;
57+ this . set ( key , shoeboxItem ) ;
58+
59+ return shoeboxItem ;
60+ }
61+ } ) ;
62+
2963export default Ember . Service . extend ( {
3064 cookies : deprecatingAlias ( 'request.cookies' , { id : 'fastboot.cookies-to-request' , until : '0.9.9' } ) ,
3165 headers : deprecatingAlias ( 'request.headers' , { id : 'fastboot.headers-to-request' , until : '0.9.9' } ) ,
3266
67+ init ( ) {
68+ this . _super ( ...arguments ) ;
69+
70+ let shoebox = Shoebox . create ( { fastboot : this } ) ;
71+ this . set ( 'shoebox' , shoebox ) ;
72+ } ,
73+
3374 host : computed ( function ( ) {
3475 deprecate (
3576 'Usage of fastboot service\'s `host` property is deprecated. Please use `request.host` instead.' ,
0 commit comments