@@ -59,6 +59,7 @@ libs.forEach((lib, i) => {
59
59
var code = fs . readFileSync ( require . resolve ( file ) , 'utf8' ) ;
60
60
var gzip = gzipSize . sync ( Terser . minify ( code ) . code ) ;
61
61
62
+ // clean up the parent
62
63
// clean up the parent
63
64
parent . textContent = '' ;
64
65
if ( before )
@@ -171,7 +172,7 @@ libs.forEach((lib, i) => {
171
172
172
173
start ( ) ;
173
174
childNodes = create1000 ( parent , diff , childNodes ) ;
174
- stop ( parent . operations . length , 1000 ) ;
175
+ stop ( parent . mutations . length , 1000 ) ;
175
176
console . assert (
176
177
verifyNodes ( parent , childNodes , 1000 ) ,
177
178
'%s 1k' ,
@@ -180,7 +181,7 @@ libs.forEach((lib, i) => {
180
181
181
182
start ( ) ;
182
183
childNodes = create1000 ( parent , diff , childNodes ) ;
183
- stop ( parent . operations . length , 2000 ) ;
184
+ stop ( parent . mutations . length , 2000 ) ;
184
185
console . assert (
185
186
verifyNodes ( parent , childNodes , 1000 ) ,
186
187
'%s replace' ,
@@ -189,7 +190,7 @@ libs.forEach((lib, i) => {
189
190
190
191
start ( ) ;
191
192
childNodes = random ( parent , diff , childNodes ) ;
192
- stop ( parent . operations . length , 1000 ) ;
193
+ stop ( parent . mutations . length , 2000 ) ;
193
194
console . assert (
194
195
verifyNodes ( parent , childNodes , 1000 ) ,
195
196
'%s random' ,
@@ -198,7 +199,7 @@ libs.forEach((lib, i) => {
198
199
199
200
start ( ) ;
200
201
childNodes = reverse ( parent , diff , childNodes ) ;
201
- stop ( parent . operations . length , 1000 ) ;
202
+ stop ( parent . mutations . length , 2000 ) ;
202
203
console . assert (
203
204
verifyNodes ( parent , childNodes , 1000 ) ,
204
205
'%s reverse' ,
@@ -207,7 +208,7 @@ libs.forEach((lib, i) => {
207
208
208
209
start ( ) ;
209
210
childNodes = clear ( parent , diff , childNodes ) ;
210
- stop ( parent . operations . length , 1000 ) ;
211
+ stop ( parent . mutations . length , 1000 ) ;
211
212
console . assert (
212
213
verifyNodes ( parent , childNodes , 0 ) ,
213
214
'%s clear' ,
@@ -218,7 +219,7 @@ libs.forEach((lib, i) => {
218
219
219
220
start ( ) ;
220
221
childNodes = append1000 ( parent , diff , childNodes ) ;
221
- stop ( parent . operations . length , 2000 ) ;
222
+ stop ( parent . mutations . length , 2000 ) ;
222
223
console . assert (
223
224
verifyNodes ( parent , childNodes , 2000 ) ,
224
225
'%s append 1k' ,
@@ -227,7 +228,7 @@ libs.forEach((lib, i) => {
227
228
228
229
start ( ) ;
229
230
childNodes = prepend1000 ( parent , diff , childNodes ) ;
230
- stop ( parent . operations . length , 1000 ) ;
231
+ stop ( parent . mutations . length , 1000 ) ;
231
232
console . assert (
232
233
verifyNodes ( parent , childNodes , 3000 ) ,
233
234
'%s prepend 1k' ,
@@ -239,7 +240,7 @@ libs.forEach((lib, i) => {
239
240
240
241
start ( ) ;
241
242
childNodes = swapRows ( parent , diff , childNodes ) ;
242
- stop ( parent . operations . length , 2 ) ;
243
+ stop ( parent . mutations . length , 4 ) ;
243
244
console . assert (
244
245
parent . childNodes [ 1 ] . textContent == 998 &&
245
246
parent . childNodes [ 998 ] . textContent == 1 &&
@@ -250,7 +251,7 @@ libs.forEach((lib, i) => {
250
251
251
252
start ( ) ;
252
253
childNodes = updateEach10thRow ( parent , diff , childNodes ) ;
253
- stop ( parent . operations . length , 200 ) ;
254
+ stop ( parent . mutations . length , 200 ) ;
254
255
console . assert (
255
256
verifyNodes ( parent , childNodes , 1000 ) ,
256
257
'%s update 10th' ,
@@ -261,7 +262,7 @@ libs.forEach((lib, i) => {
261
262
262
263
start ( ) ;
263
264
childNodes = create10000 ( parent , diff , childNodes ) ;
264
- stop ( parent . operations . length , 10000 ) ;
265
+ stop ( parent . mutations . length , 10000 ) ;
265
266
console . assert (
266
267
verifyNodes ( parent , childNodes , 10000 ) ,
267
268
'%s 10k' ,
@@ -270,7 +271,7 @@ libs.forEach((lib, i) => {
270
271
271
272
start ( ) ;
272
273
childNodes = swapRows ( parent , diff , childNodes ) ;
273
- stop ( parent . operations . length , 2 ) ;
274
+ stop ( parent . mutations . length , 4 ) ;
274
275
console . assert (
275
276
parent . childNodes [ 1 ] . textContent == 9998 &&
276
277
parent . childNodes [ 9998 ] . textContent == 1 &&
@@ -317,36 +318,41 @@ function instrument(parent) {
317
318
removeChild,
318
319
replaceChild
319
320
} = parent ;
320
- parent . operations = [ ] ;
321
+ parent . mutations = [ ] ;
321
322
parent . appendChild = function ( newNode ) {
322
- this . operations . push ( `appendChild(${ newNode . textContent } )` ) ;
323
+ const { textContent} = newNode ;
324
+ if ( newNode . parentNode )
325
+ this . mutations . push ( `append: drop(${ textContent } )` ) ;
326
+ this . mutations . push ( `append: add(${ textContent } )` ) ;
323
327
return appendChild . call ( this , newNode ) ;
324
328
} ;
325
329
parent . insertBefore = function ( newNode , oldNode ) {
326
- this . operations . push (
330
+ const { textContent} = newNode ;
331
+ if ( newNode . parentNode )
332
+ this . mutations . push ( `insert: drop(${ textContent } )` ) ;
333
+ this . mutations . push (
327
334
oldNode ?
328
- `insertBefore (${ newNode . textContent } , ${ oldNode . textContent } )` :
329
- `insertBefore (${ newNode . textContent } )`
335
+ `insert: put (${ textContent } ) before ( ${ oldNode . textContent } )` :
336
+ `insert: add (${ textContent } )`
330
337
) ;
331
338
return insertBefore . call ( this , newNode , oldNode ) ;
332
339
} ;
333
340
parent . removeChild = function ( oldNode ) {
334
- this . operations . push ( `removeChild (${ oldNode . textContent } )` ) ;
341
+ this . mutations . push ( `remove: drop (${ oldNode . textContent } )` ) ;
335
342
return removeChild . call ( this , oldNode ) ;
336
343
} ;
337
344
parent . replaceChild = function ( newNode , oldNode ) {
338
- this . operations . push (
339
- `delete#replaceChild(${ newNode . textContent } , ${ oldNode . textContent } )`
340
- ) ;
341
- this . operations . push (
342
- `insert#replaceChild(${ newNode . textContent } , ${ oldNode . textContent } )`
343
- ) ;
345
+ const { textContent} = newNode ;
346
+ this . mutations . push ( `replace: drop(${ oldNode . textContent } )` ) ;
347
+ if ( newNode . parentNode )
348
+ this . mutations . push ( `replace: drop(${ textContent } )` ) ;
349
+ this . mutations . push ( `replace: put(${ textContent } )` ) ;
344
350
return replaceChild . call ( this , newNode , oldNode ) ;
345
351
} ;
346
352
}
347
353
348
354
function reset ( parent ) {
349
- parent . operations . splice ( 0 ) ;
355
+ parent . mutations . splice ( 0 ) ;
350
356
}
351
357
352
358
function round ( num ) {
0 commit comments