@@ -12,11 +12,14 @@ const HTML_HEAD_REGEX = /^([\s\S]*<\/head>)([\s\S]*)/;
1212 * method.
1313 */
1414class Result {
15- constructor ( options ) {
15+ constructor ( options = { } ) {
16+ let { doc, html, fastbootInfo } = options ;
17+
1618 this . _instanceDestroyed = false ;
17- this . _doc = options . doc ;
18- this . _html = options . html ;
19- this . _fastbootInfo = options . fastbootInfo ;
19+
20+ this . _doc = doc ;
21+ this . _html = html ;
22+ this . _fastbootInfo = fastbootInfo ;
2023 }
2124
2225 /**
@@ -66,22 +69,19 @@ class Result {
6669 return [ html ] ;
6770 }
6871
69- let head = docParts [ 1 ] ;
70- let body = docParts [ 2 ] ;
72+ let [ , head , body ] = docParts ;
7173
7274 if ( ! head || ! body ) {
7375 throw new Error ( 'Could not idenfity head and body of the document! Make sure the document is well formed.' ) ;
7476 }
7577
76- let chunks = [ head ] ;
77- let bodyParts = body . split ( SHOEBOX_TAG_PATTERN ) ;
78- let plainBody = bodyParts [ 0 ] ;
79- chunks . push ( plainBody ) ;
78+ let [ plainBody , ...shoeboxes ] = body . split ( SHOEBOX_TAG_PATTERN ) ;
8079
81- let shoeboxes = bodyParts . splice ( 1 ) ;
82- shoeboxes . forEach ( ( shoebox ) => {
83- chunks . push ( `${ SHOEBOX_TAG_PATTERN } ${ shoebox } ` ) ;
84- } ) ;
80+ let chunks = [
81+ head ,
82+ plainBody
83+ ]
84+ . concat ( shoeboxes . map ( shoebox => `${ SHOEBOX_TAG_PATTERN } ${ shoebox } ` ) ) ;
8585
8686 return chunks ;
8787 } ) ;
@@ -114,7 +114,7 @@ class Result {
114114
115115 // Grab some metadata from the sandboxed application instance
116116 // and copy it to this Result object.
117- let instance = this . instance ;
117+ let { instance } = this ;
118118 if ( instance ) {
119119 this . _finalizeMetadata ( instance ) ;
120120 }
@@ -130,7 +130,7 @@ class Result {
130130 this . url = instance . getURL ( ) ;
131131 }
132132
133- let response = this . _fastbootInfo . response ;
133+ let { response } = this . _fastbootInfo ;
134134
135135 if ( response ) {
136136 this . headers = response . headers ;
@@ -142,8 +142,10 @@ class Result {
142142 if ( this . instance && ! this . _instanceDestroyed ) {
143143 this . _instanceDestroyed = true ;
144144 this . instance . destroy ( ) ;
145+
145146 return true ;
146147 }
148+
147149 return false ;
148150 }
149151
@@ -178,10 +180,10 @@ class Result {
178180}
179181
180182function missingTag ( tag ) {
181- return Promise . reject ( new Error ( `Fastboot was not able to find ${ tag } in base HTML. It could not replace the contents.` ) ) ;
183+ throw new Error ( `Fastboot was not able to find ${ tag } in base HTML. It could not replace the contents.` ) ;
182184}
183185
184- function insertIntoIndexHTML ( html , htmlAttributes , head , body , bodyAttributes ) {
186+ async function insertIntoIndexHTML ( html , htmlAttributes , head , body , bodyAttributes ) {
185187 if ( ! html ) { return Promise . resolve ( html ) ; }
186188 let isBodyReplaced = false ;
187189 let isHeadReplaced = false ;
@@ -210,13 +212,13 @@ function insertIntoIndexHTML(html, htmlAttributes, head, body, bodyAttributes) {
210212 }
211213
212214 if ( head && ! isHeadReplaced ) {
213- return missingTag ( '<!--EMBER_CLI_FASTBOOT_HEAD-->' ) ;
215+ missingTag ( '<!--EMBER_CLI_FASTBOOT_HEAD-->' ) ;
214216 }
215217 if ( body && ! isBodyReplaced ) {
216- return missingTag ( '<!--EMBER_CLI_FASTBOOT_BODY-->' ) ;
218+ missingTag ( '<!--EMBER_CLI_FASTBOOT_BODY-->' ) ;
217219 }
218220
219- return Promise . resolve ( html ) ;
221+ return html ;
220222}
221223
222224module . exports = Result ;
0 commit comments