Skip to content

Commit fa80261

Browse files
committed
more simplification
1 parent 0d67026 commit fa80261

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

src/generators/dom/visitors/EachBlock.js

+7-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import CodeBuilder from '../../../utils/CodeBuilder.js';
21
import deindent from '../../../utils/deindent.js';
32
import visit from '../visit.js';
43

@@ -119,24 +118,13 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea
119118
const iteration = block.getUniqueName( `${each_block}_iteration` );
120119
const _iterations = block.getUniqueName( `_${each_block}_iterations` );
121120

122-
block.builders.create.addLine( `var ${lookup} = Object.create( null );` );
123-
124-
const create = new CodeBuilder();
125-
126-
create.addBlock( deindent`
127-
var ${key} = ${each_block_value}[${i}].${node.key};
128-
${iterations}[${i}] = ${lookup}[ ${key} ] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} );
129-
` );
130-
131-
if ( state.parentNode ) {
132-
create.addLine(
133-
`${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`
134-
);
135-
}
136-
137121
block.builders.create.addBlock( deindent`
122+
var ${lookup} = Object.create( null );
123+
138124
for ( var ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
139-
${create}
125+
var ${key} = ${each_block_value}[${i}].${node.key};
126+
${iterations}[${i}] = ${lookup}[ ${key} ] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} );
127+
${state.parentNode && `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`}
140128
}
141129
` );
142130

@@ -206,21 +194,10 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea
206194
}
207195

208196
function unkeyed ( generator, block, state, node, snippet, { create_each_block, each_block_value, iterations, i, params, anchor, mountOrIntro } ) {
209-
const create = new CodeBuilder();
210-
211-
create.addLine(
212-
`${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );`
213-
);
214-
215-
if ( state.parentNode ) {
216-
create.addLine(
217-
`${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`
218-
);
219-
}
220-
221197
block.builders.create.addBlock( deindent`
222198
for ( var ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
223-
${create}
199+
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
200+
${state.parentNode && `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`}
224201
}
225202
` );
226203

0 commit comments

Comments
 (0)