File tree 5 files changed +119
-1
lines changed
src/generators/dom/visitors
5 files changed +119
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export default function visitAwaitBlock(
67
67
${ old_block } .u();
68
68
${ old_block } .d();
69
69
${ await_block } .c();
70
- ${ await_block } .m(${ anchor } .parentNode, ${ anchor } );
70
+ ${ await_block } .m(${ state . parentNode || ` ${ anchor } .parentNode` } , ${ anchor } );
71
71
}
72
72
}
73
73
@@ -142,6 +142,10 @@ export default function visitAwaitBlock(
142
142
` ) ;
143
143
}
144
144
145
+ block . builders . unmount . addBlock ( deindent `
146
+ ${ await_block } .u();
147
+ ` ) ;
148
+
145
149
block . builders . destroy . addBlock ( deindent `
146
150
${ await_token } = null;
147
151
${ await_block } .d();
Original file line number Diff line number Diff line change
1
+ let fulfil ;
2
+
3
+ let thePromise = new Promise ( f => {
4
+ fulfil = f ;
5
+ } ) ;
6
+
7
+ export default {
8
+ data : {
9
+ thePromise
10
+ } ,
11
+
12
+ html : `
13
+ <div><p>loading...</p></div>
14
+ ` ,
15
+
16
+ test ( assert , component , target ) {
17
+ fulfil ( 42 ) ;
18
+
19
+ return thePromise
20
+ . then ( ( ) => {
21
+ assert . htmlEqual ( target . innerHTML , `
22
+ <div><p>the value is 42</p></div>
23
+ ` ) ;
24
+
25
+ let reject ;
26
+
27
+ thePromise = new Promise ( ( f , r ) => {
28
+ reject = r ;
29
+ } ) ;
30
+
31
+ component . set ( {
32
+ thePromise
33
+ } ) ;
34
+
35
+ assert . htmlEqual ( target . innerHTML , `
36
+ <div><p>loading...</p></div>
37
+ ` ) ;
38
+
39
+ reject ( new Error ( 'something broke' ) ) ;
40
+
41
+ return thePromise . catch ( ( ) => { } ) ;
42
+ } )
43
+ . then ( ( ) => {
44
+ assert . htmlEqual ( target . innerHTML , `
45
+ <div><p>oh no! something broke</p></div>
46
+ ` ) ;
47
+ } ) ;
48
+ }
49
+ } ;
Original file line number Diff line number Diff line change
1
+ < div >
2
+ {{#await thePromise}}
3
+ < p > loading...</ p >
4
+ {{then theValue}}
5
+ < p > the value is {{theValue}}</ p >
6
+ {{catch theError}}
7
+ < p > oh no! {{theError.message}}</ p >
8
+ {{/await}}
9
+ </ div >
Original file line number Diff line number Diff line change
1
+ let fulfil ;
2
+
3
+ const thePromise = new Promise ( f => {
4
+ fulfil = f ;
5
+ } ) ;
6
+
7
+ export default {
8
+ data : {
9
+ show : true ,
10
+ thePromise
11
+ } ,
12
+
13
+ html : `
14
+ <p>loading...</p>
15
+ ` ,
16
+
17
+ test ( assert , component , target ) {
18
+ fulfil ( 42 ) ;
19
+
20
+ return thePromise
21
+ . then ( ( ) => {
22
+ assert . htmlEqual ( target . innerHTML , `
23
+ <p>the value is 42</p>
24
+ ` ) ;
25
+
26
+ component . set ( {
27
+ show : false
28
+ } ) ;
29
+
30
+ assert . htmlEqual ( target . innerHTML , `
31
+ <p>Else</p>
32
+ ` ) ;
33
+
34
+ component . set ( {
35
+ show : true
36
+ } ) ;
37
+
38
+ return thePromise . then ( ( ) => {
39
+ assert . htmlEqual ( target . innerHTML , `
40
+ <p>the value is 42</p>
41
+ ` ) ;
42
+ } ) ;
43
+ } ) ;
44
+ }
45
+ } ;
Original file line number Diff line number Diff line change
1
+ {{#if show}}
2
+ {{#await thePromise}}
3
+ < p > loading...</ p >
4
+ {{then theValue}}
5
+ < p > the value is {{theValue}}</ p >
6
+ {{catch theError}}
7
+ < p > oh no! {{theError.message}}</ p >
8
+ {{/await}}
9
+ {{else}}
10
+ < p > Else</ p >
11
+ {{/if}}
You can’t perform that action at this time.
0 commit comments