@@ -13,6 +13,7 @@ const jekyllFiles = {
13
13
[ jekyllComponent ( 'title-loop' ) ] : "{% for t in include.titles %}{% bookshop title title=t %}{% endfor %}" ,
14
14
[ jekyllComponent ( 'num-loop' ) ] : "{% for t in (include.min..include.max) %}{% bookshop title title=t %}{% endfor %}" ,
15
15
[ jekyllComponent ( 'wrapper' ) ] : "{% bookshop {{include.component}} bind=page %}" ,
16
+ [ jekyllComponent ( 'dynamic-loop' ) ] : "{% for props in include.t %}{% bookshop {{props._bookshop_name}} bind=props %}{% endfor %}" ,
16
17
}
17
18
18
19
const eleventyComponent = ( k ) => `components/${ k } /${ k } .eleventy.liquid` ;
@@ -22,6 +23,7 @@ const eleventyFiles = {
22
23
[ eleventyComponent ( 'title-loop' ) ] : "{% for t in titles %}{% bookshop 'title' title: t %}{% endfor %}" ,
23
24
[ eleventyComponent ( 'num-loop' ) ] : "{% for t in (min..max) %}{% bookshop 'title' title: t %}{% endfor %}" ,
24
25
[ eleventyComponent ( 'wrapper' ) ] : "{% bookshop '{{component}}' bind: page %}" ,
26
+ [ eleventyComponent ( 'dynamic-loop' ) ] : "{% for props in t %}{% bookshop '{{props._bookshop_name}}' bind: props %}{% endfor %}" ,
25
27
}
26
28
27
29
const initial = async ( liveInstance , component , props ) => {
@@ -36,8 +38,8 @@ const initialSub = async (liveInstance, component, props) => {
36
38
await liveInstance . engines [ 0 ] . render (
37
39
document . querySelector ( 'body' ) ,
38
40
'wrapper' ,
39
- { component} ,
40
- { page : props }
41
+ { component } ,
42
+ { page : props }
41
43
) ;
42
44
}
43
45
@@ -47,21 +49,21 @@ const setBody = (h) => document.querySelector('body').innerHTML = Array.isArray(
47
49
test . beforeEach ( async t => {
48
50
setBody ( '' ) ;
49
51
t . context = {
50
- jekyll : new ( getLive ( [ new JekyllEngine ( { files : jekyllFiles } ) ] ) ) ( ) ,
51
- eleventy : new ( getLive ( [ new EleventyEngine ( { files : eleventyFiles } ) ] ) ) ( )
52
+ jekyll : new ( getLive ( [ new JekyllEngine ( { files : jekyllFiles } ) ] ) ) ( ) ,
53
+ eleventy : new ( getLive ( [ new EleventyEngine ( { files : eleventyFiles } ) ] ) ) ( )
52
54
} ;
53
55
} )
54
56
55
57
for ( const impl of [ 'jekyll' , 'eleventy' ] ) {
56
58
test . serial ( `[${ impl } ]: Re-renders a simple component` , async t => {
57
- await initialSub ( t . context [ impl ] , 'title' , { title : 'Bookshop' } ) ;
59
+ await initialSub ( t . context [ impl ] , 'title' , { title : 'Bookshop' } ) ;
58
60
t . is ( getBody ( ) , [
59
61
`<!--bookshop-live name(title) params(bind: page)-->` ,
60
62
`<h1>Bookshop<\/h1>` ,
61
63
`<!--bookshop-live end-->`
62
64
] . join ( '' ) ) ;
63
65
64
- await t . context [ impl ] . update ( { page : { title : 'Live Love Laugh' } } )
66
+ await t . context [ impl ] . update ( { page : { title : 'Live Love Laugh' } } )
65
67
t . is ( getBody ( ) , [
66
68
`<!--bookshop-live name(title) params(bind: page)-->` ,
67
69
`<h1>Live Love Laugh<\/h1>` ,
@@ -70,14 +72,14 @@ for (const impl of ['jekyll', 'eleventy']) {
70
72
} ) ;
71
73
72
74
test . serial ( `[${ impl } ]: Re-renders in a loop` , async t => {
73
- await initialSub ( t . context [ impl ] , 'title-loop' , { titles : [ 'Bookshop' , 'Jekyll' , 'Eleventy' ] } ) ;
75
+ await initialSub ( t . context [ impl ] , 'title-loop' , { titles : [ 'Bookshop' , 'Jekyll' , 'Eleventy' ] } ) ;
74
76
t . regex ( getBody ( ) , / < h 1 > J e k y l l < \/ h 1 > / ) ;
75
77
76
78
let trigger = false ;
77
79
// Add event listener to the first h1 'Bookshop'
78
80
document . querySelectorAll ( 'h1' ) [ 0 ] . addEventListener ( 'click' , ( ) => trigger = true ) ;
79
81
80
- await t . context [ impl ] . update ( { page : { titles : [ 'Bookshop' , 'Hugo' , 'Eleventy' ] } } )
82
+ await t . context [ impl ] . update ( { page : { titles : [ 'Bookshop' , 'Hugo' , 'Eleventy' ] } } )
81
83
t . regex ( getBody ( ) , / < h 1 > H u g o < \/ h 1 > / ) ;
82
84
t . notRegex ( getBody ( ) , / < h 1 > J e k y l l < \/ h 1 > / ) ;
83
85
@@ -90,33 +92,89 @@ for (const impl of ['jekyll', 'eleventy']) {
90
92
} ) ;
91
93
92
94
test . serial ( `[${ impl } ]: Re-renders top-level loop` , async t => {
93
- await initial ( t . context [ impl ] , 'title-loop' , { titles : [ 'Bookshop' , 'Jekyll' , 'Eleventy' ] } ) ;
95
+ await initial ( t . context [ impl ] , 'title-loop' , { titles : [ 'Bookshop' , 'Jekyll' , 'Eleventy' ] } ) ;
94
96
t . regex ( getBody ( ) , / < h 1 > J e k y l l < \/ h 1 > / ) ;
95
97
96
- await t . context [ impl ] . update ( { titles : [ 'Bookshop' , 'Hugo' , 'Eleventy' ] } )
98
+ await t . context [ impl ] . update ( { titles : [ 'Bookshop' , 'Hugo' , 'Eleventy' ] } )
97
99
t . regex ( getBody ( ) , / < h 1 > H u g o < \/ h 1 > / ) ;
98
100
t . notRegex ( getBody ( ) , / < h 1 > J e k y l l < \/ h 1 > / ) ;
99
101
} ) ;
100
102
101
103
test . serial ( `[${ impl } ]: Re-renders range loop` , async t => {
102
- await initial ( t . context [ impl ] , 'num-loop' , { min : 0 , max : 1 } ) ;
104
+ await initial ( t . context [ impl ] , 'num-loop' , { min : 0 , max : 1 } ) ;
103
105
t . regex ( getBody ( ) , / < h 1 > 0 < \/ h 1 > .* < h 1 > 1 < \/ h 1 > / ) ;
104
106
t . notRegex ( getBody ( ) , / < h 1 > 2 < \/ h 1 > / ) ;
105
107
106
- await t . context [ impl ] . update ( { min : 4 , max : 5 } ) ;
108
+ await t . context [ impl ] . update ( { min : 4 , max : 5 } ) ;
107
109
t . regex ( getBody ( ) , / < h 1 > 4 < \/ h 1 > .* < h 1 > 5 < \/ h 1 > / ) ;
108
110
t . notRegex ( getBody ( ) , / < h 1 > 0 < \/ h 1 > / ) ;
109
111
} ) ;
110
112
113
+ test . serial ( `[${ impl } ]: Re-renders dynamic loop` , async t => {
114
+ await initial ( t . context [ impl ] , 'dynamic-loop' , {
115
+ t : [
116
+ {
117
+ _bookshop_name : 'title' ,
118
+ title : 'Outer Hello World'
119
+ } ,
120
+ {
121
+ _bookshop_name : 'dynamic-loop' ,
122
+ t : [
123
+ {
124
+ _bookshop_name : 'title' ,
125
+ title : 'First Inner Hello World'
126
+ } ,
127
+ {
128
+ _bookshop_name : 'title' ,
129
+ title : 'Second Inner Hello World'
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ } ) ;
135
+ t . regex ( getBody ( ) , / < h 1 > O u t e r H e l l o W o r l d < \/ h 1 > / ) ;
136
+ t . regex ( getBody ( ) , / < h 1 > F i r s t I n n e r H e l l o W o r l d < \/ h 1 > / ) ;
137
+ t . regex ( getBody ( ) , / < h 1 > S e c o n d I n n e r H e l l o W o r l d < \/ h 1 > / ) ;
138
+
139
+ await t . context [ impl ] . update ( {
140
+ t : [
141
+ {
142
+ _bookshop_name : 'title' ,
143
+ title : 'Outer Hello World'
144
+ } ,
145
+ {
146
+ _bookshop_name : 'dynamic-loop' ,
147
+ t : [
148
+ {
149
+ _bookshop_name : 'title' ,
150
+ title : 'First Changed Inner Hello World'
151
+ } ,
152
+ {
153
+ _bookshop_name : 'title' ,
154
+ title : 'Second Inner Hello World'
155
+ } ,
156
+ {
157
+ _bookshop_name : 'title' ,
158
+ title : 'Third Inner Hello World'
159
+ }
160
+ ]
161
+ }
162
+ ]
163
+ } )
164
+ t . regex ( getBody ( ) , / < h 1 > F i r s t C h a n g e d I n n e r H e l l o W o r l d < \/ h 1 > / ) ;
165
+ t . notRegex ( getBody ( ) , / < h 1 > F i r s t I n n e r H e l l o W o r l d < \/ h 1 > / ) ;
166
+ t . regex ( getBody ( ) , / < h 1 > T h i r d I n n e r H e l l o W o r l d < \/ h 1 > / ) ;
167
+ } ) ;
168
+
111
169
test . serial ( `[${ impl } ]: Re-renders depth first` , async t => {
112
- await initialSub ( t . context [ impl ] , 'super-title' , { one : "One" , two : "Two" , three : "Three" } ) ;
170
+ await initialSub ( t . context [ impl ] , 'super-title' , { one : "One" , two : "Two" , three : "Three" } ) ;
113
171
t . regex ( getBody ( ) , / < h 1 > O n e < \/ h 1 > / ) ;
114
172
115
173
let trigger = false ;
116
174
// Add event listener to h1 not rendered from a subcomponent 'Two'
117
175
document . querySelectorAll ( 'h1' ) [ 1 ] . addEventListener ( 'click' , ( ) => trigger = true ) ;
118
176
119
- await t . context [ impl ] . update ( { page : { one : "Uno" , two : "Two" , three : "Tres" } } )
177
+ await t . context [ impl ] . update ( { page : { one : "Uno" , two : "Two" , three : "Tres" } } )
120
178
t . regex ( getBody ( ) , / < h 1 > U n o < \/ h 1 > / ) ;
121
179
t . regex ( getBody ( ) , / < h 1 > T w o < \/ h 1 > / ) ;
122
180
t . regex ( getBody ( ) , / < h 1 > T r e s < \/ h 1 > / ) ;
0 commit comments