How to use cloneSet method in ladle

Best JavaScript code snippet using ladle

set-operations.spec.ts

Source:set-operations.spec.ts Github

copy

Full Screen

1import {add, filter, remove} from '../set-operations';2import { Batcher } from '../precompile-output/batcher';3import { cloneSet, useSetBatcher } from "./set-batcher";4xdescribe('SetOperations', () => {5 describe('add', () => {6 describe('1 operation', () => {7 describe('mutable', () => {8 describe('changed', () => {9 it('changes with mutate: true', () => {10 const s = new Set<number>([1,2]);11 let helper = add({target: s, item: 3, mutate: true})12 expect(helper).toEqual({13 /* Because was Mutated */14 initialValue: new Set([1, 2, 3]),15 mutateInitial: true,16 cloneFn: cloneSet,17 /* Because added 3 */18 hasChanged: true,19 /* Because Mutated */20 currentValue: new Set([1, 2, 3])21 })22 /* Reference holds because mutated */23 expect(helper.initialValue).toBe(s);24 expect(helper.currentValue).toBe(s); 25 })26 it ('changes with batcher mutate', () => {27 const s = new Set<number>([1,2]);28 let batcher = useSetBatcher(s, true);29 let helper = add({item: 3, batcher})30 expect(helper).toEqual({31 /* Because was Mutated */32 initialValue: new Set([1, 2, 3]),33 mutateInitial: true,34 cloneFn: cloneSet,35 /* Because added 3 */36 hasChanged: true,37 /* Because Mutated */38 currentValue: new Set([1, 2, 3])39 })40 /* Reference holds because mutated */41 expect(helper.initialValue).toBe(s);42 expect(helper.currentValue).toBe(s); 43 expect(helper).toBe(batcher);44 }) 45 })46 describe('unchanged', () => {47 it ('does not change with mutate: true', () => {48 const s = new Set<number>([1,2]);49 let helper = add({target: s, item: 2, mutate: true})50 expect(helper).toEqual({51 /* Because did not change */52 initialValue: new Set([1, 2]),53 mutateInitial: true,54 cloneFn: cloneSet,55 hasChanged: false,56 /* Because did not change */57 currentValue: new Set([1, 2])58 })59 /* Reference holds because mutated */60 expect(helper.initialValue).toBe(s);61 expect(helper.currentValue).toBe(s); 62 }) 63 64 it ('does not change with batcher mutate', () => {65 const s = new Set<number>([1,2]);66 let batcher = useSetBatcher(s, true);67 let helper = add({target: s, item: 2, batcher})68 expect(helper).toEqual({69 /* Because did not change */70 initialValue: new Set([1, 2]),71 mutateInitial: true,72 cloneFn: cloneSet,73 hasChanged: false,74 /* Because did not change */75 currentValue: new Set([1, 2])76 })77 /* Reference holds because mutated */78 expect(helper.initialValue).toBe(s);79 expect(helper.currentValue).toBe(s); 80 expect(helper).toBe(batcher);81 }) 82 })83 })84 describe('immutable', () => {85 describe('changed', () => {86 it('creates new copy with mutate: false (no key)', () => {87 const s = new Set<number>([1,2]);88 let helper = add({target: s, item: 3})89 expect(helper).toEqual({90 /* Because Immutable */91 initialValue: new Set([1, 2]),92 mutateInitial: false,93 cloneFn: cloneSet,94 /* Because added 3 */95 hasChanged: true,96 /* Because Mutated */97 currentValue: new Set([1, 2, 3])98 })99 /* Reference holds because mutated */100 expect(helper.initialValue).toBe(s);101 expect(helper.currentValue).not.toBe(s); 102 })103 it('creates new copy with batcher immutable', () => {104 const s = new Set<number>([1,2]);105 const batcher = useSetBatcher(s);106 let helper = add({target: s, item: 3, batcher})107 expect(helper).toEqual({108 /* Because Immutable */109 initialValue: new Set([1, 2]),110 mutateInitial: false,111 cloneFn: cloneSet,112 /* Because added 3 */113 hasChanged: true,114 /* Because Mutated */115 currentValue: new Set([1, 2, 3])116 })117 /* Reference holds because mutated */118 expect(helper.initialValue).toBe(s);119 expect(helper.currentValue).not.toBe(s); 120 expect(helper).toBe(batcher);121 })122 })123 describe('unchanged', () => {124 it('does not change with mutate: false (no key)', () => {125 const s = new Set<number>([1,2]);126 let helper = add({target: s, item: 2})127 expect(helper).toEqual({128 /* Because did not change */129 initialValue: new Set([1, 2]),130 mutateInitial: false,131 cloneFn: cloneSet,132 /* Because added 3 */133 hasChanged: false,134 /* Because did not change */135 currentValue: new Set([1, 2])136 })137 /* Reference holds because mutated */138 expect(helper.initialValue).toBe(s);139 expect(helper.currentValue).toBe(s); 140 })141 it('does not change with batcher immutable', () => {142 const s = new Set<number>([1,2]);143 let batcher = useSetBatcher(s);144 let helper = add({target: s, item: 2, batcher})145 expect(helper).toEqual({146 /* Because did not change */147 initialValue: new Set([1, 2]),148 mutateInitial: false,149 cloneFn: cloneSet,150 /* Because added 3 */151 hasChanged: false,152 /* Because did not change */153 currentValue: new Set([1, 2])154 })155 /* Reference holds because mutated */156 expect(helper.initialValue).toBe(s);157 expect(helper.currentValue).toBe(s); 158 expect(helper).toBe(batcher); 159 })160 })161 })162 })163 describe('2 operations', () => {164 it('mutable changed, changed', () => {165 const s = new Set<number>([1,2]);166 let helper = add({target: s, item: 3, mutate: true})167 expect(helper).toEqual({168 /* Because was Mutated */169 initialValue: new Set([1, 2, 3]),170 mutateInitial: true,171 cloneFn: cloneSet,172 /* Because added 3 */173 hasChanged: true,174 /* Because Mutated */175 currentValue: new Set([1, 2, 3])176 })177 /* Reference holds because mutated */178 expect(helper.initialValue).toBe(s);179 expect(helper.currentValue).toBe(s); 180 181 helper = add({batcher: helper, item: 4})182 expect(helper).toEqual({183 /* Because was Mutated */184 initialValue: new Set([1, 2, 3, 4]),185 mutateInitial: true,186 cloneFn: cloneSet,187 /* Because added 3 */188 hasChanged: true,189 /* Because Mutated */190 currentValue: new Set([1, 2, 3, 4])191 })192 /* Reference holds because mutated */193 expect(helper.initialValue).toBe(s);194 expect(helper.currentValue).toBe(s); 195 })196 it('mutable changed, not changed ', () => {197 const s = new Set<number>([1,2]);198 let batcher = useSetBatcher(s, true)199 let helper = add({item: 3, batcher})200 expect(helper).toEqual({201 /* Because was Mutated */202 initialValue: new Set([1, 2, 3]),203 mutateInitial: true,204 cloneFn: cloneSet,205 /* Because added 3 */206 hasChanged: true,207 /* Because Mutated */208 currentValue: new Set([1, 2, 3])209 })210 /* Reference holds because mutated */211 expect(helper.initialValue).toBe(s);212 expect(helper.currentValue).toBe(s); 213 expect(helper).toBe(batcher); 214 215 /* Should not change */216 helper = add({item: 2, batcher})217 expect(helper).toEqual({218 /* same ref */219 initialValue: new Set([1, 2, 3]),220 mutateInitial: true,221 cloneFn: cloneSet,222 /* Because added 3 */223 hasChanged: true,224 /* same ref */225 currentValue: new Set([1, 2, 3])226 })227 /* Reference holds because mutated */228 expect(helper.initialValue).toBe(s);229 expect(helper.currentValue).toBe(s); 230 expect(helper).toBe(batcher); 231 }) 232 233 it('mutable not changed, changed', () => {234 const s = new Set<number>([1, 2]);235 const batcher = useSetBatcher(s, true);236 let helper = add({item: 2, batcher})237 expect(helper).toEqual({238 /* Because not Mutated */239 initialValue: new Set([1, 2]),240 mutateInitial: true,241 cloneFn: cloneSet,242 hasChanged: false,243 /* Because not mutated */244 currentValue: new Set([1, 2])245 })246 /* Reference holds because not mutated */247 expect(helper.initialValue).toBe(s);248 expect(helper.currentValue).toBe(s); 249 250 /* Now we change it */251 helper = add({batcher: helper, item: 4})252 expect(helper).toEqual({253 /* Because was Mutated */254 initialValue: new Set([1, 2, 4]),255 mutateInitial: true,256 cloneFn: cloneSet,257 /* Because added 3 */258 hasChanged: true,259 /* Because Mutated */260 currentValue: new Set([1, 2, 4])261 })262 /* Reference holds because mutated */263 expect(helper.initialValue).toBe(s);264 expect(helper.currentValue).toBe(s); 265 })266 it('mutable not changed, not changed', () => {267 const s = new Set<number>([1, 2]);268 const batcher = useSetBatcher(s, true);269 let helper = add({item: 2, batcher})270 expect(helper).toEqual({271 /* Because not Mutated */272 initialValue: new Set([1, 2]),273 mutateInitial: true,274 cloneFn: cloneSet,275 hasChanged: false,276 /* Because not mutated */277 currentValue: new Set([1, 2])278 })279 /* Reference holds because not mutated */280 expect(helper.initialValue).toBe(s);281 expect(helper.currentValue).toBe(s); 282 283 /* Don't change it */284 helper = add({batcher: helper, item: 1})285 expect(helper).toEqual({286 /* Because was Mutated */287 initialValue: new Set([1, 2]),288 mutateInitial: true,289 cloneFn: cloneSet,290 /* Because added 3 */291 hasChanged: false,292 /* Because Mutated */293 currentValue: new Set([1, 2])294 })295 /* Reference holds because mutated */296 expect(helper.initialValue).toBe(s);297 expect(helper.currentValue).toBe(s); 298 }) 299 it('immutable changed, changed', () => {300 const s = new Set<number>([1, 2]);301 let batcher = useSetBatcher(s);302 let helper = add({batcher, item: 3})303 expect(helper).toEqual({304 initialValue: new Set([1, 2]),305 mutateInitial: false,306 cloneFn: cloneSet,307 /* Because added 3 */308 hasChanged: true,309 /* Because cloned */310 currentValue: new Set([1, 2, 3])311 })312 expect(helper.initialValue).toBe(s);313 expect(helper.currentValue).not.toBe(s); 314 315 let helper2 = add({batcher: helper, item: 4})316 expect(helper2).toEqual({317 initialValue: new Set([1, 2]),318 mutateInitial: false,319 cloneFn: cloneSet,320 /* Because added 3 */321 hasChanged: true,322 /* Because Mutated */323 currentValue: new Set([1, 2, 3, 4])324 })325 expect(helper2.initialValue).toBe(s);326 expect(helper2.currentValue).not.toBe(s);327 expect(helper2).toBe(helper); 328 })329 it('immutable changed, not changed', () => {330 const s = new Set<number>([1, 2]);331 let batcher = useSetBatcher(s);332 let helper = add({batcher, item: 3})333 expect(helper).toEqual({334 initialValue: new Set([1, 2]),335 mutateInitial: false,336 cloneFn: cloneSet,337 /* Because added 3 */338 hasChanged: true,339 /* Because cloned */340 currentValue: new Set([1, 2, 3])341 })342 expect(helper.initialValue).toBe(s);343 expect(helper.currentValue).not.toBe(s); 344 345 let helper2 = add({batcher: helper, item: 1})346 expect(helper2).toEqual({347 initialValue: new Set([1, 2]),348 mutateInitial: false,349 cloneFn: cloneSet,350 /* Because added 3 */351 hasChanged: true,352 /* Because Mutated */353 currentValue: new Set([1, 2, 3])354 })355 expect(helper2.initialValue).toBe(s);356 expect(helper2.currentValue).not.toBe(s);357 expect(helper2).toBe(helper); 358 }) 359 360 it('immutable not changed, changed', () => {361 const s = new Set<number>([1, 2]);362 let batcher = useSetBatcher(s);363 let helper = add({batcher, item: 1})364 expect(helper).toEqual({365 initialValue: new Set([1, 2]),366 mutateInitial: false,367 cloneFn: cloneSet,368 hasChanged: false,369 /* Because cloned */370 currentValue: new Set([1, 2])371 })372 expect(helper.initialValue).toBe(s);373 expect(helper.currentValue).toBe(s); 374 375 let helper2 = add({batcher: helper, item: 3})376 expect(helper2).toEqual({377 initialValue: new Set([1, 2]),378 mutateInitial: false,379 cloneFn: cloneSet,380 /* Because added 3 */381 hasChanged: true,382 /* Because Mutated */383 currentValue: new Set([1, 2, 3])384 })385 expect(helper2.initialValue).toBe(s);386 expect(helper2.currentValue).not.toBe(s);387 expect(helper2).toBe(helper); 388 }) 389 390 it('immutable not changed, not changed', () => {391 const s = new Set<number>([1, 2]);392 let batcher = useSetBatcher(s);393 let helper = add({batcher, item: 1})394 expect(helper).toEqual({395 initialValue: new Set([1, 2]),396 mutateInitial: false,397 cloneFn: cloneSet,398 hasChanged: false,399 /* Because cloned */400 currentValue: new Set([1, 2])401 })402 expect(helper.initialValue).toBe(s);403 expect(helper.currentValue).toBe(s); 404 405 let helper2 = add({batcher: helper, item: 1})406 expect(helper2).toEqual({407 initialValue: new Set([1, 2]),408 mutateInitial: false,409 cloneFn: cloneSet,410 /* Because added 3 */411 hasChanged: false,412 /* Because Mutated */413 currentValue: new Set([1, 2])414 })415 expect(helper2.initialValue).toBe(s);416 expect(helper2.currentValue).toBe(s);417 expect(helper2).toBe(helper); 418 }) 419 })420 describe('3 operations', () => {421 describe('mutable', () => {422 it('mutable changed, changed, changed', () => {423 const s = new Set<number>([1,2]);424 let batcher = useSetBatcher(s, true);425 let helper = add({batcher, item: 3})426 expect(helper).toEqual({427 /* Because was Mutated */428 initialValue: new Set([1, 2, 3]),429 mutateInitial: true,430 cloneFn: cloneSet,431 /* Because added 3 */432 hasChanged: true,433 /* Because Mutated */434 currentValue: new Set([1, 2, 3])435 })436 /* Reference holds because mutated */437 expect(helper.initialValue).toBe(s);438 expect(helper.currentValue).toBe(s); 439 440 helper = add({batcher: helper, item: 4})441 expect(helper).toEqual({442 /* Because was Mutated */443 initialValue: new Set([1, 2, 3, 4]),444 mutateInitial: true,445 cloneFn: cloneSet,446 /* Because added 3 */447 hasChanged: true,448 /* Because Mutated */449 currentValue: new Set([1, 2, 3, 4])450 })451 /* Reference holds because mutated */452 expect(helper.initialValue).toBe(s);453 expect(helper.currentValue).toBe(s); 454 455 helper = add({batcher: helper, item: 5})456 expect(helper).toEqual({457 /* Because was Mutated */458 initialValue: new Set([1, 2, 3, 4, 5]),459 mutateInitial: true,460 cloneFn: cloneSet,461 /* Because added 3 */462 hasChanged: true,463 /* Because Mutated */464 currentValue: new Set([1, 2, 3, 4, 5])465 })466 /* Reference holds because mutated */467 expect(helper.initialValue).toBe(s);468 expect(helper.currentValue).toBe(s); 469 })470 471 it('mutable changed, changed, not changed', () => {472 const s = new Set<number>([1,2]);473 let batcher = useSetBatcher(s, true);474 let helper = add({batcher, item: 3})475 expect(helper).toEqual({476 /* Because was Mutated */477 initialValue: new Set([1, 2, 3]),478 mutateInitial: true,479 cloneFn: cloneSet,480 /* Because added 3 */481 hasChanged: true,482 /* Because Mutated */483 currentValue: new Set([1, 2, 3])484 })485 /* Reference holds because mutated */486 expect(helper.initialValue).toBe(s);487 expect(helper.currentValue).toBe(s); 488 489 helper = add({batcher: helper, item: 4})490 expect(helper).toEqual({491 /* Because was Mutated */492 initialValue: new Set([1, 2, 3, 4]),493 mutateInitial: true,494 cloneFn: cloneSet,495 /* Because added 3 */496 hasChanged: true,497 /* Because Mutated */498 currentValue: new Set([1, 2, 3, 4])499 })500 /* Reference holds because mutated */501 expect(helper.initialValue).toBe(s);502 expect(helper.currentValue).toBe(s); 503 504 helper = add({batcher: helper, item: 4})505 expect(helper).toEqual({506 /* Because was Mutated */507 initialValue: new Set([1, 2, 3, 4]),508 mutateInitial: true,509 cloneFn: cloneSet,510 /* Because added 3 */511 hasChanged: true,512 /* Because Mutated */513 currentValue: new Set([1, 2, 3, 4])514 })515 /* Reference holds because mutated */516 expect(helper.initialValue).toBe(s);517 expect(helper.currentValue).toBe(s); 518 })519 520 it('mutable changed, not changed, changed', () => {521 const s = new Set<number>([1,2]);522 let batcher = useSetBatcher(s, true);523 let helper = add({batcher, item: 3})524 expect(helper).toEqual({525 /* Because was Mutated */526 initialValue: new Set([1, 2, 3]),527 mutateInitial: true,528 cloneFn: cloneSet,529 /* Because added 3 */530 hasChanged: true,531 /* Because Mutated */532 currentValue: new Set([1, 2, 3])533 })534 /* Reference holds because mutated */535 expect(helper.initialValue).toBe(s);536 expect(helper.currentValue).toBe(s); 537 538 helper = add({batcher: helper, item: 3})539 expect(helper).toEqual({540 /* Because was Mutated */541 initialValue: new Set([1, 2, 3]),542 mutateInitial: true,543 cloneFn: cloneSet,544 /* Because added 3 */545 hasChanged: true,546 /* Because Mutated */547 currentValue: new Set([1, 2, 3])548 })549 /* Reference holds because mutated */550 expect(helper.initialValue).toBe(s);551 expect(helper.currentValue).toBe(s); 552 553 helper = add({batcher: helper, item: 4})554 expect(helper).toEqual({555 /* Because was Mutated */556 initialValue: new Set([1, 2, 3, 4]),557 mutateInitial: true,558 cloneFn: cloneSet,559 /* Because added 3 */560 hasChanged: true,561 /* Because Mutated */562 currentValue: new Set([1, 2, 3, 4])563 })564 /* Reference holds because mutated */565 expect(helper.initialValue).toBe(s);566 expect(helper.currentValue).toBe(s); 567 })568 569 it('mutable changed, not changed, not changed', () => {570 const s = new Set<number>([1,2]);571 let batcher = useSetBatcher(s, true);572 let helper = add({batcher, item: 3})573 expect(helper).toEqual({574 /* Because was Mutated */575 initialValue: new Set([1, 2, 3]),576 mutateInitial: true,577 cloneFn: cloneSet,578 /* Because added 3 */579 hasChanged: true,580 /* Because Mutated */581 currentValue: new Set([1, 2, 3])582 })583 /* Reference holds because mutated */584 expect(helper.initialValue).toBe(s);585 expect(helper.currentValue).toBe(s); 586 587 helper = add({batcher: helper, item: 2})588 expect(helper).toEqual({589 /* Because was Mutated */590 initialValue: new Set([1, 2, 3]),591 mutateInitial: true,592 cloneFn: cloneSet,593 /* Because added 3 */594 hasChanged: true,595 /* Because Mutated */596 currentValue: new Set([1, 2, 3])597 })598 /* Reference holds because mutated */599 expect(helper.initialValue).toBe(s);600 expect(helper.currentValue).toBe(s); 601 602 helper = add({batcher: helper, item: 1})603 expect(helper).toEqual({604 /* Because was Mutated */605 initialValue: new Set([1, 2, 3]),606 mutateInitial: true,607 cloneFn: cloneSet,608 /* Because added 3 */609 hasChanged: true,610 /* Because Mutated */611 currentValue: new Set([1, 2, 3])612 })613 /* Reference holds because mutated */614 expect(helper.initialValue).toBe(s);615 expect(helper.currentValue).toBe(s); 616 })617 618 it('mutable not changed, changed, changed', () => {619 const s = new Set<number>([1,2]);620 let batcher = useSetBatcher(s, true);621 let helper = add({batcher, item: 1})622 expect(helper).toEqual({623 /* Because was Mutated */624 initialValue: new Set([1, 2]),625 mutateInitial: true,626 cloneFn: cloneSet,627 /* Because added 3 */628 hasChanged: false,629 /* Because Mutated */630 currentValue: new Set([1, 2])631 })632 /* Reference holds because mutated */633 expect(helper.initialValue).toBe(s);634 expect(helper.currentValue).toBe(s); 635 636 helper = add({batcher: helper, item: 4})637 expect(helper).toEqual({638 /* Because was Mutated */639 initialValue: new Set([1, 2, 4]),640 mutateInitial: true,641 cloneFn: cloneSet,642 /* Because added 3 */643 hasChanged: true,644 /* Because Mutated */645 currentValue: new Set([1, 2, 4])646 })647 /* Reference holds because mutated */648 expect(helper.initialValue).toBe(s);649 expect(helper.currentValue).toBe(s); 650 651 helper = add({batcher: helper, item: 5})652 expect(helper).toEqual({653 /* Because was Mutated */654 initialValue: new Set([1, 2, 4, 5]),655 mutateInitial: true,656 cloneFn: cloneSet,657 /* Because added 3 */658 hasChanged: true,659 /* Because Mutated */660 currentValue: new Set([1, 2, 4, 5])661 })662 /* Reference holds because mutated */663 expect(helper.initialValue).toBe(s);664 expect(helper.currentValue).toBe(s); 665 })666 667 it('mutable not changed, changed, not changed', () => {668 const s = new Set<number>([1,2]);669 let batcher = useSetBatcher(s, true);670 let helper = add({batcher, item: 1})671 expect(helper).toEqual({672 /* Because was Mutated */673 initialValue: new Set([1, 2]),674 mutateInitial: true,675 cloneFn: cloneSet,676 /* Because added 3 */677 hasChanged: false,678 /* Because Mutated */679 currentValue: new Set([1, 2])680 })681 /* Reference holds because mutated */682 expect(helper.initialValue).toBe(s);683 expect(helper.currentValue).toBe(s); 684 685 helper = add({batcher: helper, item: 4})686 expect(helper).toEqual({687 /* Because was Mutated */688 initialValue: new Set([1, 2, 4]),689 mutateInitial: true,690 cloneFn: cloneSet,691 /* Because added 3 */692 hasChanged: true,693 /* Because Mutated */694 currentValue: new Set([1, 2, 4])695 })696 /* Reference holds because mutated */697 expect(helper.initialValue).toBe(s);698 expect(helper.currentValue).toBe(s); 699 700 helper = add({batcher: helper, item: 2})701 expect(helper).toEqual({702 /* Because was Mutated */703 initialValue: new Set([1, 2, 4]),704 mutateInitial: true,705 cloneFn: cloneSet,706 /* Because added 3 */707 hasChanged: true,708 /* Because Mutated */709 currentValue: new Set([1, 2, 4])710 })711 /* Reference holds because mutated */712 expect(helper.initialValue).toBe(s);713 expect(helper.currentValue).toBe(s); 714 })715 716 it('mutable not changed, not changed, changed', () => {717 const s = new Set<number>([1,2]);718 let batcher = useSetBatcher(s, true);719 let helper = add({batcher, item: 1})720 expect(helper).toEqual({721 /* Because was Mutated */722 initialValue: new Set([1, 2]),723 mutateInitial: true,724 cloneFn: cloneSet,725 /* Because added 3 */726 hasChanged: false,727 /* Because Mutated */728 currentValue: new Set([1, 2])729 })730 /* Reference holds because mutated */731 expect(helper.initialValue).toBe(s);732 expect(helper.currentValue).toBe(s); 733 734 helper = add({batcher: helper, item: 2})735 expect(helper).toEqual({736 /* Because was Mutated */737 initialValue: new Set([1, 2]),738 mutateInitial: true,739 cloneFn: cloneSet,740 /* Because added 3 */741 hasChanged: false,742 /* Because Mutated */743 currentValue: new Set([1, 2])744 })745 /* Reference holds because mutated */746 expect(helper.initialValue).toBe(s);747 expect(helper.currentValue).toBe(s); 748 749 helper = add({batcher: helper, item: 4})750 expect(helper).toEqual({751 /* Because was Mutated */752 initialValue: new Set([1, 2, 4]),753 mutateInitial: true,754 cloneFn: cloneSet,755 /* Because added 3 */756 hasChanged: true,757 /* Because Mutated */758 currentValue: new Set([1, 2, 4])759 })760 /* Reference holds because mutated */761 expect(helper.initialValue).toBe(s);762 expect(helper.currentValue).toBe(s); 763 })764 765 it('mutable not changed, not changed, not changed', () => {766 const s = new Set<number>([1,2]);767 let batcher = useSetBatcher(s, true);768 let helper = add({batcher, item: 1})769 expect(helper).toEqual({770 /* Because was Mutated */771 initialValue: new Set([1, 2]),772 mutateInitial: true,773 cloneFn: cloneSet,774 /* Because added 3 */775 hasChanged: false,776 /* Because Mutated */777 currentValue: new Set([1, 2])778 })779 /* Reference holds because mutated */780 expect(helper.initialValue).toBe(s);781 expect(helper.currentValue).toBe(s); 782 783 helper = add({batcher: helper, item: 2})784 expect(helper).toEqual({785 /* Because was Mutated */786 initialValue: new Set([1, 2]),787 mutateInitial: true,788 cloneFn: cloneSet,789 /* Because added 3 */790 hasChanged: false,791 /* Because Mutated */792 currentValue: new Set([1, 2])793 })794 /* Reference holds because mutated */795 expect(helper.initialValue).toBe(s);796 expect(helper.currentValue).toBe(s); 797 798 helper = add({batcher: helper, item: 2})799 expect(helper).toEqual({800 /* Because was Mutated */801 initialValue: new Set([1, 2]),802 mutateInitial: true,803 cloneFn: cloneSet,804 /* Because added 3 */805 hasChanged: false,806 /* Because Mutated */807 currentValue: new Set([1, 2])808 })809 /* Reference holds because mutated */810 expect(helper.initialValue).toBe(s);811 expect(helper.currentValue).toBe(s); 812 })813 })814 815 describe('immutable', () => {816 it('immutable changed, changed, changed', () => {817 const s = new Set<number>([1,2]);818 let batcher = useSetBatcher(s);819 let helper = add({batcher, item: 3})820 expect(helper).toEqual({821 /* Because was Mutated */822 initialValue: new Set([1, 2]),823 mutateInitial: false,824 cloneFn: cloneSet,825 /* Because added 3 */826 hasChanged: true,827 /* Because Mutated */828 currentValue: new Set([1, 2, 3])829 })830 /* Reference holds because mutated */831 expect(helper.initialValue).toBe(s);832 expect(helper.currentValue).not.toBe(s); 833 834 let s1 = helper.currentValue;835 836 helper = add({batcher: helper, item: 4})837 expect(helper).toEqual({838 /* Because was Mutated */839 initialValue: new Set([1, 2]),840 mutateInitial: false,841 cloneFn: cloneSet,842 /* Because added 3 */843 hasChanged: true,844 /* Because Mutated */845 currentValue: new Set([1, 2, 3, 4])846 })847 /* Reference holds because mutated */848 expect(helper.initialValue).toBe(s);849 expect(helper.currentValue).not.toBe(s); 850 expect(helper.currentValue).toBe(s1);851 852 helper = add({batcher: helper, item: 5})853 expect(helper).toEqual({854 /* Because was Mutated */855 initialValue: new Set([1, 2]),856 mutateInitial: false,857 cloneFn: cloneSet,858 /* Because added 3 */859 hasChanged: true,860 /* Because Mutated */861 currentValue: new Set([1, 2, 3, 4, 5])862 })863 /* Reference holds because mutated */864 expect(helper.initialValue).toBe(s);865 expect(helper.currentValue).not.toBe(s); 866 expect(helper.currentValue).toBe(s1);867 })868 869 it('immutable changed, changed, not changed', () => {870 const s = new Set<number>([1, 2]);871 let batcher = useSetBatcher(s);872 let helper = add({batcher, item: 3})873 expect(helper).toEqual({874 /* Because was Mutated */875 initialValue: new Set([1, 2]),876 mutateInitial: false,877 cloneFn: cloneSet,878 /* Because added 3 */879 hasChanged: true,880 /* Because Mutated */881 currentValue: new Set([1, 2, 3])882 })883 /* Reference holds because mutated */884 expect(helper.initialValue).toBe(s);885 expect(helper.currentValue).not.toBe(s); 886 887 let s1 = helper.currentValue;888 889 helper = add({batcher: helper, item: 4})890 expect(helper).toEqual({891 /* Because was Mutated */892 initialValue: new Set([1, 2]),893 mutateInitial: false,894 cloneFn: cloneSet,895 /* Because added 3 */896 hasChanged: true,897 /* Because Mutated */898 currentValue: new Set([1, 2, 3, 4])899 })900 /* Reference holds because mutated */901 expect(helper.initialValue).toBe(s);902 expect(helper.currentValue).not.toBe(s); 903 expect(helper.currentValue).toBe(s1);904 905 helper = add({batcher: helper, item: 2})906 expect(helper).toEqual({907 /* Because was Mutated */908 initialValue: new Set([1, 2]),909 mutateInitial: false,910 cloneFn: cloneSet,911 /* Because added 3 */912 hasChanged: true,913 /* Because Mutated */914 currentValue: new Set([1, 2, 3, 4])915 })916 /* Reference holds because mutated */917 expect(helper.initialValue).toBe(s);918 expect(helper.currentValue).not.toBe(s); 919 expect(helper.currentValue).toBe(s1); 920 })921 922 it('immutable changed, not changed, changed', () => {923 const s = new Set<number>([1,2]);924 let batcher = useSetBatcher(s);925 let helper = add({batcher, item: 3})926 expect(helper).toEqual({927 /* Because was Mutated */928 initialValue: new Set([1, 2]),929 mutateInitial: false,930 cloneFn: cloneSet,931 /* Because added 3 */932 hasChanged: true,933 /* Because Mutated */934 currentValue: new Set([1, 2, 3])935 })936 /* Reference holds because mutated */937 expect(helper.initialValue).toBe(s);938 expect(helper.currentValue).not.toBe(s); 939 940 let s1 = helper.currentValue;941 942 helper = add({batcher: helper, item: 1})943 expect(helper).toEqual({944 /* Because was Mutated */945 initialValue: new Set([1, 2]),946 mutateInitial: false,947 cloneFn: cloneSet,948 /* Because added 3 */949 hasChanged: true,950 /* Because Mutated */951 currentValue: new Set([1, 2, 3])952 })953 /* Reference holds because mutated */954 expect(helper.initialValue).toBe(s);955 expect(helper.currentValue).not.toBe(s); 956 expect(helper.currentValue).toBe(s1);957 958 helper = add({batcher: helper, item: 5})959 expect(helper).toEqual({960 /* Because was Mutated */961 initialValue: new Set([1, 2]),962 mutateInitial: false,963 cloneFn: cloneSet,964 /* Because added 3 */965 hasChanged: true,966 /* Because Mutated */967 currentValue: new Set([1, 2, 3, 5])968 })969 /* Reference holds because mutated */970 expect(helper.initialValue).toBe(s);971 expect(helper.currentValue).not.toBe(s); 972 expect(helper.currentValue).toBe(s1); 973 })974 975 it('immutable changed, not changed, not changed', () => {976 const s = new Set<number>([1,2]);977 let batcher = useSetBatcher(s);978 let helper = add({batcher, item: 3})979 expect(helper).toEqual({980 /* Because was Mutated */981 initialValue: new Set([1, 2]),982 mutateInitial: false,983 cloneFn: cloneSet,984 /* Because added 3 */985 hasChanged: true,986 /* Because Mutated */987 currentValue: new Set([1, 2, 3])988 })989 /* Reference holds because mutated */990 expect(helper.initialValue).toBe(s);991 expect(helper.currentValue).not.toBe(s); 992 993 let s1 = helper.currentValue;994 995 helper = add({batcher: helper, item: 1})996 expect(helper).toEqual({997 /* Because was Mutated */998 initialValue: new Set([1, 2]),999 mutateInitial: false,1000 cloneFn: cloneSet,1001 /* Because added 3 */1002 hasChanged: true,1003 /* Because Mutated */1004 currentValue: new Set([1, 2, 3])1005 })1006 /* Reference holds because mutated */1007 expect(helper.initialValue).toBe(s);1008 expect(helper.currentValue).not.toBe(s); 1009 expect(helper.currentValue).toBe(s1);1010 1011 helper = add({batcher: helper, item: 2})1012 expect(helper).toEqual({1013 /* Because was Mutated */1014 initialValue: new Set([1, 2]),1015 mutateInitial: false,1016 cloneFn: cloneSet,1017 /* Because added 3 */1018 hasChanged: true,1019 /* Because Mutated */1020 currentValue: new Set([1, 2, 3])1021 })1022 /* Reference holds because mutated */1023 expect(helper.initialValue).toBe(s);1024 expect(helper.currentValue).not.toBe(s); 1025 expect(helper.currentValue).toBe(s1); 1026 })1027 1028 it('immutable not changed, changed, changed', () => {1029 const s = new Set<number>([1, 2]);1030 let batcher = useSetBatcher(s);1031 let helper = add({batcher, item: 1})1032 expect(helper).toEqual({1033 /* Because was Mutated */1034 initialValue: new Set([1, 2]),1035 mutateInitial: false,1036 cloneFn: cloneSet,1037 /* Because added 3 */1038 hasChanged: false,1039 /* Because Mutated */1040 currentValue: new Set([1, 2])1041 })1042 /* Reference holds because mutated */1043 expect(helper.initialValue).toBe(s);1044 expect(helper.currentValue).toBe(s); 1045 1046 helper = add({batcher: helper, item: 4})1047 expect(helper).toEqual({1048 initialValue: new Set([1, 2]),1049 mutateInitial: false,1050 cloneFn: cloneSet,1051 /* Because added 3 */1052 hasChanged: true,1053 /* Because Mutated */1054 currentValue: new Set([1, 2, 4])1055 })1056 expect(helper.initialValue).toBe(s);1057 expect(helper.currentValue).not.toBe(s); 1058 1059 let s1 = helper.currentValue;1060 1061 helper = add({batcher: helper, item: 5})1062 expect(helper).toEqual({1063 /* Because was Mutated */1064 initialValue: new Set([1, 2]),1065 mutateInitial: false,1066 cloneFn: cloneSet,1067 /* Because added 3 */1068 hasChanged: true,1069 /* Because Mutated */1070 currentValue: new Set([1, 2, 4, 5])1071 })1072 /* Reference holds because mutated */1073 expect(helper.initialValue).toBe(s);1074 expect(helper.currentValue).not.toBe(s); 1075 expect(helper.currentValue).toBe(s1)1076 })1077 1078 it('immutable not changed, changed, not changed', () => {1079 const s = new Set<number>([1, 2]);1080 let batcher = useSetBatcher(s);1081 let helper = add({batcher, item: 1})1082 expect(helper).toEqual({1083 /* Because was Mutated */1084 initialValue: new Set([1, 2]),1085 mutateInitial: false,1086 cloneFn: cloneSet,1087 /* Because added 3 */1088 hasChanged: false,1089 /* Because Mutated */1090 currentValue: new Set([1, 2])1091 })1092 /* Reference holds because mutated */1093 expect(helper.initialValue).toBe(s);1094 expect(helper.currentValue).toBe(s); 1095 1096 helper = add({batcher: helper, item: 4})1097 expect(helper).toEqual({1098 initialValue: new Set([1, 2]),1099 mutateInitial: false,1100 cloneFn: cloneSet,1101 /* Because added 3 */1102 hasChanged: true,1103 /* Because Mutated */1104 currentValue: new Set([1, 2, 4])1105 })1106 expect(helper.initialValue).toBe(s);1107 expect(helper.currentValue).not.toBe(s); 1108 1109 let s1 = helper.currentValue;1110 1111 helper = add({batcher: helper, item: 2})1112 expect(helper).toEqual({1113 /* Because was Mutated */1114 initialValue: new Set([1, 2]),1115 mutateInitial: false,1116 cloneFn: cloneSet,1117 /* Because added 3 */1118 hasChanged: true,1119 /* Because Mutated */1120 currentValue: new Set([1, 2, 4])1121 })1122 /* Reference holds because mutated */1123 expect(helper.initialValue).toBe(s);1124 expect(helper.currentValue).not.toBe(s); 1125 expect(helper.currentValue).toBe(s1) 1126 })1127 1128 it('immutable not changed, not changed, changed', () => {1129 const s = new Set<number>([1, 2]);1130 let batcher = useSetBatcher(s);1131 let helper = add({batcher, item: 1})1132 expect(helper).toEqual({1133 /* Because was Mutated */1134 initialValue: new Set([1, 2]),1135 mutateInitial: false,1136 cloneFn: cloneSet,1137 /* Because added 3 */1138 hasChanged: false,1139 /* Because Mutated */1140 currentValue: new Set([1, 2])1141 })1142 /* Reference holds because mutated */1143 expect(helper.initialValue).toBe(s);1144 expect(helper.currentValue).toBe(s); 1145 1146 helper = add({batcher: helper, item: 2})1147 expect(helper).toEqual({1148 initialValue: new Set([1, 2]),1149 mutateInitial: false,1150 cloneFn: cloneSet,1151 /* Because added 3 */1152 hasChanged: false,1153 /* Because Mutated */1154 currentValue: new Set([1, 2])1155 })1156 expect(helper.initialValue).toBe(s);1157 expect(helper.currentValue).toBe(s); 1158 1159 let s1 = helper.currentValue;1160 1161 helper = add({batcher: helper, item: 4})1162 expect(helper).toEqual({1163 /* Because was Mutated */1164 initialValue: new Set([1, 2]),1165 mutateInitial: false,1166 cloneFn: cloneSet,1167 /* Because added 3 */1168 hasChanged: true,1169 /* Because Mutated */1170 currentValue: new Set([1, 2, 4])1171 })1172 /* Reference holds because mutated */1173 expect(helper.initialValue).toBe(s);1174 expect(helper.currentValue).not.toBe(s); 1175 expect(helper.currentValue).not.toBe(s1); 1176 })1177 1178 it('immutable not changed, not changed, not changed', () => {1179 const s = new Set<number>([1, 2]);1180 let batcher = useSetBatcher(s);1181 let helper = add({batcher, item: 1})1182 expect(helper).toEqual({1183 /* Because was Mutated */1184 initialValue: new Set([1, 2]),1185 mutateInitial: false,1186 cloneFn: cloneSet,1187 /* Because added 3 */1188 hasChanged: false,1189 /* Because Mutated */1190 currentValue: new Set([1, 2])1191 })1192 /* Reference holds because mutated */1193 expect(helper.initialValue).toBe(s);1194 expect(helper.currentValue).toBe(s); 1195 1196 helper = add({batcher: helper, item: 2})1197 expect(helper).toEqual({1198 initialValue: new Set([1, 2]),1199 mutateInitial: false,1200 cloneFn: cloneSet,1201 /* Because added 3 */1202 hasChanged: false,1203 /* Because Mutated */1204 currentValue: new Set([1, 2])1205 })1206 expect(helper.initialValue).toBe(s);1207 expect(helper.currentValue).toBe(s); 1208 1209 let s1 = helper.currentValue;1210 1211 helper = add({batcher: helper, item: 1})1212 expect(helper).toEqual({1213 /* Because was Mutated */1214 initialValue: new Set([1, 2]),1215 mutateInitial: false,1216 cloneFn: cloneSet,1217 /* Because added 3 */1218 hasChanged: false,1219 /* Because Mutated */1220 currentValue: new Set([1, 2])1221 })1222 /* Reference holds because mutated */1223 expect(helper.initialValue).toBe(s);1224 expect(helper.currentValue).toBe(s); 1225 expect(helper.currentValue).toBe(s1); 1226 })1227 })1228 })1229 1230 })1231 1232 describe('remove', () => {1233 describe('1 operation', () => {1234 describe('mutable', () => {1235 describe('changed', () => {1236 it('changes with mutate: true', () => {1237 const s = new Set<number>([1, 2, 3]);1238 let helper = remove({target: s, item: 3, mutate: true})1239 expect(helper).toEqual({1240 /* Because was Mutated */1241 initialValue: new Set([1, 2]),1242 mutateInitial: true,1243 cloneFn: cloneSet,1244 /* Because added 3 */1245 hasChanged: true,1246 /* Because Mutated */1247 currentValue: new Set([1, 2])1248 })1249 /* Reference holds because mutated */1250 expect(helper.initialValue).toBe(s);1251 expect(helper.currentValue).toBe(s); 1252 })1253 it ('changes with batcher mutate', () => {1254 const s = new Set<number>([1, 2, 3]);1255 let batcher = useSetBatcher(s, true);1256 let helper = remove({item: 3, batcher})1257 expect(helper).toEqual({1258 /* Because was Mutated */1259 initialValue: new Set([1, 2]),1260 mutateInitial: true,1261 cloneFn: cloneSet,1262 /* Because added 3 */1263 hasChanged: true,1264 /* Because Mutated */1265 currentValue: new Set([1, 2])1266 })1267 /* Reference holds because mutated */1268 expect(helper.initialValue).toBe(s);1269 expect(helper.currentValue).toBe(s); 1270 expect(helper).toBe(batcher);1271 }) 1272 })1273 describe('unchanged', () => {1274 it ('does not change with mutate: true', () => {1275 const s = new Set<number>([1, 2]);1276 let helper = remove({target: s, item: 3, mutate: true})1277 expect(helper).toEqual({1278 /* Because did not change */1279 initialValue: new Set([1, 2]),1280 mutateInitial: true,1281 cloneFn: cloneSet,1282 hasChanged: false,1283 /* Because did not change */1284 currentValue: new Set([1, 2])1285 })1286 /* Reference holds because mutated */1287 expect(helper.initialValue).toBe(s);1288 expect(helper.currentValue).toBe(s); 1289 }) 1290 1291 it ('does not change with batcher mutate', () => {1292 const s = new Set<number>([1, 2]);1293 let batcher = useSetBatcher(s, true);1294 let helper = remove({target: s, item: 3, batcher})1295 expect(helper).toEqual({1296 /* Because did not change */1297 initialValue: new Set([1, 2]),1298 mutateInitial: true,1299 cloneFn: cloneSet,1300 hasChanged: false,1301 /* Because did not change */1302 currentValue: new Set([1, 2])1303 })1304 /* Reference holds because mutated */1305 expect(helper.initialValue).toBe(s);1306 expect(helper.currentValue).toBe(s); 1307 expect(helper).toBe(batcher);1308 }) 1309 })1310 })1311 describe('immutable', () => {1312 describe('changed', () => {1313 it('creates new copy with mutate: false (no key)', () => {1314 const s = new Set<number>([1,2]);1315 let helper = remove({target: s, item: 2})1316 expect(helper).toEqual({1317 /* Because Immutable */1318 initialValue: new Set([1, 2]),1319 mutateInitial: false,1320 cloneFn: cloneSet,1321 /* Because added 3 */1322 hasChanged: true,1323 /* Because Mutated */1324 currentValue: new Set([1])1325 })1326 /* Reference holds because mutated */1327 expect(helper.initialValue).toBe(s);1328 expect(helper.currentValue).not.toBe(s); 1329 })1330 it('creates new copy with batcher immutable', () => {1331 const s = new Set<number>([1,2]);1332 const batcher = useSetBatcher(s);1333 let helper = remove({target: s, item: 2, batcher})1334 expect(helper).toEqual({1335 /* Because Immutable */1336 initialValue: new Set([1, 2]),1337 mutateInitial: false,1338 cloneFn: cloneSet,1339 /* Because added 3 */1340 hasChanged: true,1341 /* Because Mutated */1342 currentValue: new Set([1])1343 })1344 /* Reference holds because mutated */1345 expect(helper.initialValue).toBe(s);1346 expect(helper.currentValue).not.toBe(s); 1347 expect(helper).toBe(batcher);1348 })1349 })1350 describe('unchanged', () => {1351 it('does not change with mutate: false (no key)', () => {1352 const s = new Set<number>([1, 2]);1353 let helper = remove({target: s, item: 3})1354 expect(helper).toEqual({1355 /* Because did not change */1356 initialValue: new Set([1, 2]),1357 mutateInitial: false,1358 cloneFn: cloneSet,1359 /* Because added 3 */1360 hasChanged: false,1361 /* Because did not change */1362 currentValue: new Set([1, 2])1363 })1364 /* Reference holds because mutated */1365 expect(helper.initialValue).toBe(s);1366 expect(helper.currentValue).toBe(s); 1367 })1368 it('does not change with batcher immutable', () => {1369 const s = new Set<number>([1, 2]);1370 let batcher = useSetBatcher(s);1371 let helper = remove({target: s, item: 3, batcher})1372 expect(helper).toEqual({1373 /* Because did not change */1374 initialValue: new Set([1, 2]),1375 mutateInitial: false,1376 cloneFn: cloneSet,1377 /* Because added 3 */1378 hasChanged: false,1379 /* Because did not change */1380 currentValue: new Set([1, 2])1381 })1382 /* Reference holds because mutated */1383 expect(helper.initialValue).toBe(s);1384 expect(helper.currentValue).toBe(s); 1385 expect(helper).toBe(batcher); 1386 })1387 })1388 })1389 1390 })1391 describe('3 operations', () => {1392 describe('mutable', () => {1393 it('mutable changed, changed, changed', () => {1394 const s = new Set<number>([1, 2, 3]);1395 let batcher = useSetBatcher(s, true);1396 let helper = remove({batcher, item: 3})1397 expect(helper).toEqual({1398 /* Because was Mutated */1399 initialValue: new Set([1, 2]),1400 mutateInitial: true,1401 cloneFn: cloneSet,1402 /* Because added 3 */1403 hasChanged: true,1404 /* Because Mutated */1405 currentValue: new Set([1, 2])1406 })1407 /* Reference holds because mutated */1408 expect(helper.initialValue).toBe(s);1409 expect(helper.currentValue).toBe(s); 1410 1411 helper = remove({batcher: helper, item: 2})1412 expect(helper).toEqual({1413 /* Because was Mutated */1414 initialValue: new Set([1]),1415 mutateInitial: true,1416 cloneFn: cloneSet,1417 /* Because added 3 */1418 hasChanged: true,1419 /* Because Mutated */1420 currentValue: new Set([1])1421 })1422 /* Reference holds because mutated */1423 expect(helper.initialValue).toBe(s);1424 expect(helper.currentValue).toBe(s); 1425 1426 helper = remove({batcher: helper, item: 1})1427 expect(helper).toEqual({1428 /* Because was Mutated */1429 initialValue: new Set([]),1430 mutateInitial: true,1431 cloneFn: cloneSet,1432 /* Because added 3 */1433 hasChanged: true,1434 /* Because Mutated */1435 currentValue: new Set([])1436 })1437 /* Reference holds because mutated */1438 expect(helper.initialValue).toBe(s);1439 expect(helper.currentValue).toBe(s); 1440 })1441 1442 it('mutable changed, changed, not changed', () => {1443 const s = new Set<number>([1, 2, 3]);1444 let batcher = useSetBatcher(s, true);1445 let helper = remove({batcher, item: 3})1446 expect(helper).toEqual({1447 /* Because was Mutated */1448 initialValue: new Set([1, 2]),1449 mutateInitial: true,1450 cloneFn: cloneSet,1451 /* Because added 3 */1452 hasChanged: true,1453 /* Because Mutated */1454 currentValue: new Set([1, 2])1455 })1456 /* Reference holds because mutated */1457 expect(helper.initialValue).toBe(s);1458 expect(helper.currentValue).toBe(s); 1459 1460 helper = remove({batcher: helper, item: 2})1461 expect(helper).toEqual({1462 /* Because was Mutated */1463 initialValue: new Set([1]),1464 mutateInitial: true,1465 cloneFn: cloneSet,1466 /* Because added 3 */1467 hasChanged: true,1468 /* Because Mutated */1469 currentValue: new Set([1])1470 })1471 /* Reference holds because mutated */1472 expect(helper.initialValue).toBe(s);1473 expect(helper.currentValue).toBe(s); 1474 1475 helper = remove({batcher: helper, item: 4})1476 expect(helper).toEqual({1477 /* Because was Mutated */1478 initialValue: new Set([1]),1479 mutateInitial: true,1480 cloneFn: cloneSet,1481 /* Because added 3 */1482 hasChanged: true,1483 /* Because Mutated */1484 currentValue: new Set([1])1485 })1486 /* Reference holds because mutated */1487 expect(helper.initialValue).toBe(s);1488 expect(helper.currentValue).toBe(s); 1489 })1490 1491 it('mutable changed, not changed, changed', () => {1492 const s = new Set<number>([1,2, 3]);1493 let batcher = useSetBatcher(s, true);1494 let helper = remove({batcher, item: 3})1495 expect(helper).toEqual({1496 /* Because was Mutated */1497 initialValue: new Set([1, 2]),1498 mutateInitial: true,1499 cloneFn: cloneSet,1500 /* Because added 3 */1501 hasChanged: true,1502 /* Because Mutated */1503 currentValue: new Set([1, 2])1504 })1505 /* Reference holds because mutated */1506 expect(helper.initialValue).toBe(s);1507 expect(helper.currentValue).toBe(s); 1508 1509 helper = remove({batcher: helper, item: 4})1510 expect(helper).toEqual({1511 /* Because was Mutated */1512 initialValue: new Set([1, 2]),1513 mutateInitial: true,1514 cloneFn: cloneSet,1515 /* Because added 3 */1516 hasChanged: true,1517 /* Because Mutated */1518 currentValue: new Set([1, 2])1519 })1520 /* Reference holds because mutated */1521 expect(helper.initialValue).toBe(s);1522 expect(helper.currentValue).toBe(s); 1523 1524 helper = remove({batcher: helper, item: 1})1525 expect(helper).toEqual({1526 /* Because was Mutated */1527 initialValue: new Set([2]),1528 mutateInitial: true,1529 cloneFn: cloneSet,1530 /* Because added 3 */1531 hasChanged: true,1532 /* Because Mutated */1533 currentValue: new Set([2])1534 })1535 /* Reference holds because mutated */1536 expect(helper.initialValue).toBe(s);1537 expect(helper.currentValue).toBe(s); 1538 })1539 1540 it('mutable changed, not changed, not changed', () => {1541 const s = new Set<number>([1, 2]);1542 let batcher = useSetBatcher(s, true);1543 let helper = remove({batcher, item: 2})1544 expect(helper).toEqual({1545 /* Because was Mutated */1546 initialValue: new Set([1]),1547 mutateInitial: true,1548 cloneFn: cloneSet,1549 /* Because added 3 */1550 hasChanged: true,1551 /* Because Mutated */1552 currentValue: new Set([1])1553 })1554 /* Reference holds because mutated */1555 expect(helper.initialValue).toBe(s);1556 expect(helper.currentValue).toBe(s); 1557 1558 helper = remove({batcher: helper, item: 3})1559 expect(helper).toEqual({1560 /* Because was Mutated */1561 initialValue: new Set([1]),1562 mutateInitial: true,1563 cloneFn: cloneSet,1564 /* Because added 3 */1565 hasChanged: true,1566 /* Because Mutated */1567 currentValue: new Set([1])1568 })1569 /* Reference holds because mutated */1570 expect(helper.initialValue).toBe(s);1571 expect(helper.currentValue).toBe(s); 1572 1573 helper = remove({batcher: helper, item: 4})1574 expect(helper).toEqual({1575 /* Because was Mutated */1576 initialValue: new Set([1]),1577 mutateInitial: true,1578 cloneFn: cloneSet,1579 /* Because added 3 */1580 hasChanged: true,1581 /* Because Mutated */1582 currentValue: new Set([1])1583 })1584 /* Reference holds because mutated */1585 expect(helper.initialValue).toBe(s);1586 expect(helper.currentValue).toBe(s); 1587 })1588 1589 it('mutable not changed, changed, changed', () => {1590 const s = new Set<number>([1, 2]);1591 let batcher = useSetBatcher(s, true);1592 let helper = remove({batcher, item: 5})1593 expect(helper).toEqual({1594 /* Because was Mutated */1595 initialValue: new Set([1, 2]),1596 mutateInitial: true,1597 cloneFn: cloneSet,1598 /* Because added 3 */1599 hasChanged: false,1600 /* Because Mutated */1601 currentValue: new Set([1, 2])1602 })1603 /* Reference holds because mutated */1604 expect(helper.initialValue).toBe(s);1605 expect(helper.currentValue).toBe(s); 1606 1607 helper = remove({batcher: helper, item: 2})1608 expect(helper).toEqual({1609 /* Because was Mutated */1610 initialValue: new Set([1]),1611 mutateInitial: true,1612 cloneFn: cloneSet,1613 /* Because added 3 */1614 hasChanged: true,1615 /* Because Mutated */1616 currentValue: new Set([1])1617 })1618 /* Reference holds because mutated */1619 expect(helper.initialValue).toBe(s);1620 expect(helper.currentValue).toBe(s); 1621 1622 helper = remove({batcher: helper, item: 1})1623 expect(helper).toEqual({1624 /* Because was Mutated */1625 initialValue: new Set([]),1626 mutateInitial: true,1627 cloneFn: cloneSet,1628 /* Because added 3 */1629 hasChanged: true,1630 /* Because Mutated */1631 currentValue: new Set([])1632 })1633 /* Reference holds because mutated */1634 expect(helper.initialValue).toBe(s);1635 expect(helper.currentValue).toBe(s); 1636 })1637 1638 it('mutable not changed, changed, not changed', () => {1639 const s = new Set<number>([1,2]);1640 let batcher = useSetBatcher(s, true);1641 let helper = remove({batcher, item: 6})1642 expect(helper).toEqual({1643 /* Because was Mutated */1644 initialValue: new Set([1, 2]),1645 mutateInitial: true,1646 cloneFn: cloneSet,1647 /* Because added 3 */1648 hasChanged: false,1649 /* Because Mutated */1650 currentValue: new Set([1, 2])1651 })1652 /* Reference holds because mutated */1653 expect(helper.initialValue).toBe(s);1654 expect(helper.currentValue).toBe(s); 1655 1656 helper = remove({batcher: helper, item: 2})1657 expect(helper).toEqual({1658 /* Because was Mutated */1659 initialValue: new Set([1]),1660 mutateInitial: true,1661 cloneFn: cloneSet,1662 /* Because added 3 */1663 hasChanged: true,1664 /* Because Mutated */1665 currentValue: new Set([1])1666 })1667 /* Reference holds because mutated */1668 expect(helper.initialValue).toBe(s);1669 expect(helper.currentValue).toBe(s); 1670 1671 helper = remove({batcher: helper, item: 7})1672 expect(helper).toEqual({1673 /* Because was Mutated */1674 initialValue: new Set([1]),1675 mutateInitial: true,1676 cloneFn: cloneSet,1677 /* Because added 3 */1678 hasChanged: true,1679 /* Because Mutated */1680 currentValue: new Set([1])1681 })1682 /* Reference holds because mutated */1683 expect(helper.initialValue).toBe(s);1684 expect(helper.currentValue).toBe(s); 1685 })1686 1687 it('mutable not changed, not changed, changed', () => {1688 const s = new Set<number>([1,2]);1689 let batcher = useSetBatcher(s, true);1690 let helper = remove({batcher, item: 3})1691 expect(helper).toEqual({1692 /* Because was Mutated */1693 initialValue: new Set([1, 2]),1694 mutateInitial: true,1695 cloneFn: cloneSet,1696 /* Because added 3 */1697 hasChanged: false,1698 /* Because Mutated */1699 currentValue: new Set([1, 2])1700 })1701 /* Reference holds because mutated */1702 expect(helper.initialValue).toBe(s);1703 expect(helper.currentValue).toBe(s); 1704 1705 helper = remove({batcher: helper, item: 4})1706 expect(helper).toEqual({1707 /* Because was Mutated */1708 initialValue: new Set([1, 2]),1709 mutateInitial: true,1710 cloneFn: cloneSet,1711 /* Because added 3 */1712 hasChanged: false,1713 /* Because Mutated */1714 currentValue: new Set([1, 2])1715 })1716 /* Reference holds because mutated */1717 expect(helper.initialValue).toBe(s);1718 expect(helper.currentValue).toBe(s); 1719 1720 helper = remove({batcher: helper, item: 1})1721 expect(helper).toEqual({1722 /* Because was Mutated */1723 initialValue: new Set([2]),1724 mutateInitial: true,1725 cloneFn: cloneSet,1726 /* Because added 3 */1727 hasChanged: true,1728 /* Because Mutated */1729 currentValue: new Set([2])1730 })1731 /* Reference holds because mutated */1732 expect(helper.initialValue).toBe(s);1733 expect(helper.currentValue).toBe(s); 1734 })1735 1736 it('mutable not changed, not changed, not changed', () => {1737 const s = new Set<number>([1,2]);1738 let batcher = useSetBatcher(s, true);1739 let helper = remove({batcher, item: 3})1740 expect(helper).toEqual({1741 /* Because was Mutated */1742 initialValue: new Set([1, 2]),1743 mutateInitial: true,1744 cloneFn: cloneSet,1745 /* Because added 3 */1746 hasChanged: false,1747 /* Because Mutated */1748 currentValue: new Set([1, 2])1749 })1750 /* Reference holds because mutated */1751 expect(helper.initialValue).toBe(s);1752 expect(helper.currentValue).toBe(s); 1753 1754 helper = remove({batcher: helper, item: 4})1755 expect(helper).toEqual({1756 /* Because was Mutated */1757 initialValue: new Set([1, 2]),1758 mutateInitial: true,1759 cloneFn: cloneSet,1760 /* Because added 3 */1761 hasChanged: false,1762 /* Because Mutated */1763 currentValue: new Set([1, 2])1764 })1765 /* Reference holds because mutated */1766 expect(helper.initialValue).toBe(s);1767 expect(helper.currentValue).toBe(s); 1768 1769 helper = remove({batcher: helper, item: 5})1770 expect(helper).toEqual({1771 /* Because was Mutated */1772 initialValue: new Set([1, 2]),1773 mutateInitial: true,1774 cloneFn: cloneSet,1775 /* Because added 3 */1776 hasChanged: false,1777 /* Because Mutated */1778 currentValue: new Set([1, 2])1779 })1780 /* Reference holds because mutated */1781 expect(helper.initialValue).toBe(s);1782 expect(helper.currentValue).toBe(s); 1783 })1784 })1785 1786 describe('immutable', () => {1787 it('immutable changed, changed, changed', () => {1788 const s = new Set<number>([1, 2, 3]);1789 let batcher = useSetBatcher(s);1790 let helper = remove({batcher, item: 3})1791 expect(helper).toEqual({1792 /* Because was Mutated */1793 initialValue: new Set([1, 2, 3]),1794 mutateInitial: false,1795 cloneFn: cloneSet,1796 /* Because added 3 */1797 hasChanged: true,1798 /* Because Mutated */1799 currentValue: new Set([1, 2])1800 })1801 /* Reference holds because mutated */1802 expect(helper.initialValue).toBe(s);1803 expect(helper.currentValue).not.toBe(s); 1804 1805 let s1 = helper.currentValue;1806 1807 helper = remove({batcher: helper, item: 2})1808 expect(helper).toEqual({1809 /* Because was Mutated */1810 initialValue: new Set([1, 2, 3]),1811 mutateInitial: false,1812 cloneFn: cloneSet,1813 /* Because added 3 */1814 hasChanged: true,1815 /* Because Mutated */1816 currentValue: new Set([1])1817 })1818 /* Reference holds because mutated */1819 expect(helper.initialValue).toBe(s);1820 expect(helper.currentValue).not.toBe(s); 1821 expect(helper.currentValue).toBe(s1);1822 1823 helper = remove({batcher: helper, item: 1})1824 expect(helper).toEqual({1825 /* Because was Mutated */1826 initialValue: new Set([1, 2, 3]),1827 mutateInitial: false,1828 cloneFn: cloneSet,1829 /* Because added 3 */1830 hasChanged: true,1831 /* Because Mutated */1832 currentValue: new Set([])1833 })1834 /* Reference holds because mutated */1835 expect(helper.initialValue).toBe(s);1836 expect(helper.currentValue).not.toBe(s); 1837 expect(helper.currentValue).toBe(s1);1838 })1839 1840 it('immutable changed, changed, not changed', () => {1841 const s = new Set<number>([1, 2, 3]);1842 let batcher = useSetBatcher(s);1843 let helper = remove({batcher, item: 3})1844 expect(helper).toEqual({1845 /* Because was Mutated */1846 initialValue: new Set([1, 2, 3]),1847 mutateInitial: false,1848 cloneFn: cloneSet,1849 /* Because added 3 */1850 hasChanged: true,1851 /* Because Mutated */1852 currentValue: new Set([1, 2])1853 })1854 /* Reference holds because mutated */1855 expect(helper.initialValue).toBe(s);1856 expect(helper.currentValue).not.toBe(s); 1857 1858 let s1 = helper.currentValue;1859 1860 helper = remove({batcher: helper, item: 2})1861 expect(helper).toEqual({1862 /* Because was Mutated */1863 initialValue: new Set([1, 2, 3]),1864 mutateInitial: false,1865 cloneFn: cloneSet,1866 /* Because added 3 */1867 hasChanged: true,1868 /* Because Mutated */1869 currentValue: new Set([1])1870 })1871 /* Reference holds because mutated */1872 expect(helper.initialValue).toBe(s);1873 expect(helper.currentValue).not.toBe(s); 1874 expect(helper.currentValue).toBe(s1);1875 1876 helper = remove({batcher: helper, item: 4})1877 expect(helper).toEqual({1878 /* Because was Mutated */1879 initialValue: new Set([1, 2, 3]),1880 mutateInitial: false,1881 cloneFn: cloneSet,1882 /* Because added 3 */1883 hasChanged: true,1884 /* Because Mutated */1885 currentValue: new Set([1])1886 })1887 /* Reference holds because mutated */1888 expect(helper.initialValue).toBe(s);1889 expect(helper.currentValue).not.toBe(s); 1890 expect(helper.currentValue).toBe(s1); 1891 })1892 1893 it('immutable changed, not changed, changed', () => {1894 const s = new Set<number>([1, 2]);1895 let batcher = useSetBatcher(s);1896 let helper = remove({batcher, item: 1})1897 expect(helper).toEqual({1898 /* Because was Mutated */1899 initialValue: new Set([1, 2]),1900 mutateInitial: false,1901 cloneFn: cloneSet,1902 /* Because added 3 */1903 hasChanged: true,1904 /* Because Mutated */1905 currentValue: new Set([2])1906 })1907 /* Reference holds because mutated */1908 expect(helper.initialValue).toBe(s);1909 expect(helper.currentValue).not.toBe(s); 1910 1911 let s1 = helper.currentValue;1912 1913 helper = remove({batcher: helper, item: 4})1914 expect(helper).toEqual({1915 /* Because was Mutated */1916 initialValue: new Set([1, 2]),1917 mutateInitial: false,1918 cloneFn: cloneSet,1919 /* Because added 3 */1920 hasChanged: true,1921 /* Because Mutated */1922 currentValue: new Set([2])1923 })1924 /* Reference holds because mutated */1925 expect(helper.initialValue).toBe(s);1926 expect(helper.currentValue).not.toBe(s); 1927 expect(helper.currentValue).toBe(s1);1928 1929 helper = remove({batcher: helper, item: 2})1930 expect(helper).toEqual({1931 /* Because was Mutated */1932 initialValue: new Set([1, 2]),1933 mutateInitial: false,1934 cloneFn: cloneSet,1935 /* Because added 3 */1936 hasChanged: true,1937 /* Because Mutated */1938 currentValue: new Set([])1939 })1940 /* Reference holds because mutated */1941 expect(helper.initialValue).toBe(s);1942 expect(helper.currentValue).not.toBe(s); 1943 expect(helper.currentValue).toBe(s1); 1944 })1945 1946 it('immutable changed, not changed, not changed', () => {1947 const s = new Set<number>([1,2]);1948 let batcher = useSetBatcher(s);1949 let helper = remove({batcher, item: 2})1950 expect(helper).toEqual({1951 /* Because was Mutated */1952 initialValue: new Set([1, 2]),1953 mutateInitial: false,1954 cloneFn: cloneSet,1955 /* Because added 3 */1956 hasChanged: true,1957 /* Because Mutated */1958 currentValue: new Set([1])1959 })1960 /* Reference holds because mutated */1961 expect(helper.initialValue).toBe(s);1962 expect(helper.currentValue).not.toBe(s); 1963 1964 let s1 = helper.currentValue;1965 1966 helper = remove({batcher: helper, item: 4})1967 expect(helper).toEqual({1968 /* Because was Mutated */1969 initialValue: new Set([1, 2]),1970 mutateInitial: false,1971 cloneFn: cloneSet,1972 /* Because added 3 */1973 hasChanged: true,1974 /* Because Mutated */1975 currentValue: new Set([1])1976 })1977 /* Reference holds because mutated */1978 expect(helper.initialValue).toBe(s);1979 expect(helper.currentValue).not.toBe(s); 1980 expect(helper.currentValue).toBe(s1);1981 1982 helper = remove({batcher: helper, item: 5})1983 expect(helper).toEqual({1984 /* Because was Mutated */1985 initialValue: new Set([1, 2]),1986 mutateInitial: false,1987 cloneFn: cloneSet,1988 /* Because added 3 */1989 hasChanged: true,1990 /* Because Mutated */1991 currentValue: new Set([1])1992 })1993 /* Reference holds because mutated */1994 expect(helper.initialValue).toBe(s);1995 expect(helper.currentValue).not.toBe(s); 1996 expect(helper.currentValue).toBe(s1); 1997 })1998 1999 it('immutable not changed, changed, changed', () => {2000 const s = new Set<number>([1, 2]);2001 let batcher = useSetBatcher(s);2002 let helper = remove({batcher, item: 5})2003 expect(helper).toEqual({2004 /* Because was Mutated */2005 initialValue: new Set([1, 2]),2006 mutateInitial: false,2007 cloneFn: cloneSet,2008 /* Because added 3 */2009 hasChanged: false,2010 /* Because Mutated */2011 currentValue: new Set([1, 2])2012 })2013 /* Reference holds because mutated */2014 expect(helper.initialValue).toBe(s);2015 expect(helper.currentValue).toBe(s); 2016 2017 helper = remove({batcher: helper, item: 2})2018 expect(helper).toEqual({2019 initialValue: new Set([1, 2]),2020 mutateInitial: false,2021 cloneFn: cloneSet,2022 /* Because added 3 */2023 hasChanged: true,2024 /* Because Mutated */2025 currentValue: new Set([1])2026 })2027 expect(helper.initialValue).toBe(s);2028 expect(helper.currentValue).not.toBe(s); 2029 2030 let s1 = helper.currentValue;2031 2032 helper = remove({batcher: helper, item: 1})2033 expect(helper).toEqual({2034 /* Because was Mutated */2035 initialValue: new Set([1, 2]),2036 mutateInitial: false,2037 cloneFn: cloneSet,2038 /* Because added 3 */2039 hasChanged: true,2040 /* Because Mutated */2041 currentValue: new Set([])2042 })2043 /* Reference holds because mutated */2044 expect(helper.initialValue).toBe(s);2045 expect(helper.currentValue).not.toBe(s); 2046 expect(helper.currentValue).toBe(s1)2047 })2048 2049 it('immutable not changed, changed, not changed', () => {2050 const s = new Set<number>([1, 2]);2051 let batcher = useSetBatcher(s);2052 let helper = remove({batcher, item: 3})2053 expect(helper).toEqual({2054 /* Because was Mutated */2055 initialValue: new Set([1, 2]),2056 mutateInitial: false,2057 cloneFn: cloneSet,2058 /* Because added 3 */2059 hasChanged: false,2060 /* Because Mutated */2061 currentValue: new Set([1, 2])2062 })2063 /* Reference holds because mutated */2064 expect(helper.initialValue).toBe(s);2065 expect(helper.currentValue).toBe(s); 2066 2067 helper = remove({batcher: helper, item: 1})2068 expect(helper).toEqual({2069 initialValue: new Set([1, 2]),2070 mutateInitial: false,2071 cloneFn: cloneSet,2072 /* Because added 3 */2073 hasChanged: true,2074 /* Because Mutated */2075 currentValue: new Set([2])2076 })2077 expect(helper.initialValue).toBe(s);2078 expect(helper.currentValue).not.toBe(s); 2079 2080 let s1 = helper.currentValue;2081 2082 helper = remove({batcher: helper, item: 3})2083 expect(helper).toEqual({2084 /* Because was Mutated */2085 initialValue: new Set([1, 2]),2086 mutateInitial: false,2087 cloneFn: cloneSet,2088 /* Because added 3 */2089 hasChanged: true,2090 /* Because Mutated */2091 currentValue: new Set([2])2092 })2093 /* Reference holds because mutated */2094 expect(helper.initialValue).toBe(s);2095 expect(helper.currentValue).not.toBe(s); 2096 expect(helper.currentValue).toBe(s1) 2097 })2098 2099 it('immutable not changed, not changed, changed', () => {2100 const s = new Set<number>([1, 2]);2101 let batcher = useSetBatcher(s);2102 let helper = remove({batcher, item: 3})2103 expect(helper).toEqual({2104 /* Because was Mutated */2105 initialValue: new Set([1, 2]),2106 mutateInitial: false,2107 cloneFn: cloneSet,2108 /* Because added 3 */2109 hasChanged: false,2110 /* Because Mutated */2111 currentValue: new Set([1, 2])2112 })2113 /* Reference holds because mutated */2114 expect(helper.initialValue).toBe(s);2115 expect(helper.currentValue).toBe(s); 2116 2117 helper = remove({batcher: helper, item: 5})2118 expect(helper).toEqual({2119 initialValue: new Set([1, 2]),2120 mutateInitial: false,2121 cloneFn: cloneSet,2122 /* Because added 3 */2123 hasChanged: false,2124 /* Because Mutated */2125 currentValue: new Set([1, 2])2126 })2127 expect(helper.initialValue).toBe(s);2128 expect(helper.currentValue).toBe(s); 2129 2130 let s1 = helper.currentValue;2131 2132 helper = remove({batcher: helper, item: 2})2133 expect(helper).toEqual({2134 /* Because was Mutated */2135 initialValue: new Set([1, 2]),2136 mutateInitial: false,2137 cloneFn: cloneSet,2138 /* Because added 3 */2139 hasChanged: true,2140 /* Because Mutated */2141 currentValue: new Set([1])2142 })2143 /* Reference holds because mutated */2144 expect(helper.initialValue).toBe(s);2145 expect(helper.currentValue).not.toBe(s); 2146 expect(helper.currentValue).not.toBe(s1); 2147 })2148 2149 it('immutable not changed, not changed, not changed', () => {2150 const s = new Set<number>([1, 2, 3]);2151 let batcher = useSetBatcher(s);2152 let helper = remove({batcher, item: 4})2153 expect(helper).toEqual({2154 /* Because was Mutated */2155 initialValue: new Set([1, 2, 3]),2156 mutateInitial: false,2157 cloneFn: cloneSet,2158 /* Because added 3 */2159 hasChanged: false,2160 /* Because Mutated */2161 currentValue: new Set([1, 2, 3])2162 })2163 /* Reference holds because mutated */2164 expect(helper.initialValue).toBe(s);2165 expect(helper.currentValue).toBe(s); 2166 2167 helper = remove({batcher: helper, item: 5})2168 expect(helper).toEqual({2169 initialValue: new Set([1, 2, 3]),2170 mutateInitial: false,2171 cloneFn: cloneSet,2172 /* Because added 3 */2173 hasChanged: false,2174 /* Because Mutated */2175 currentValue: new Set([1, 2, 3])2176 })2177 expect(helper.initialValue).toBe(s);2178 expect(helper.currentValue).toBe(s); 2179 2180 let s1 = helper.currentValue;2181 2182 helper = remove({batcher: helper, item: 6})2183 expect(helper).toEqual({2184 /* Because was Mutated */2185 initialValue: new Set([1, 2, 3]),2186 mutateInitial: false,2187 cloneFn: cloneSet,2188 /* Because added 3 */2189 hasChanged: false,2190 /* Because Mutated */2191 currentValue: new Set([1, 2, 3])2192 })2193 /* Reference holds because mutated */2194 expect(helper.initialValue).toBe(s);2195 expect(helper.currentValue).toBe(s); 2196 expect(helper.currentValue).toBe(s1); 2197 })2198 })2199 })2200 2201 })2202 describe('filter', () => {2203 describe('1 operation', () => {2204 describe('mutable', () => {2205 describe('changed', () => {2206 it('changes with mutate: true', () => {2207 const s = new Set<number>([1, 2, 3, 4, 5]);2208 let helper = filter({target: s, fn: (i) => i < 4, mutate: true})2209 expect(helper).toEqual({2210 /* Because was Mutated */2211 initialValue: new Set([1, 2, 3]),2212 mutateInitial: true,2213 cloneFn: cloneSet,2214 /* Because added 3 */2215 hasChanged: true,2216 /* Because Mutated */2217 currentValue: new Set([1, 2, 3])2218 })2219 /* Reference holds because mutated */2220 expect(helper.initialValue).toBe(s);2221 expect(helper.currentValue).toBe(s); 2222 })2223 it ('changes with batcher mutate', () => {2224 const s = new Set<number>([1, 2, 3, 4, 5]);2225 let batcher = useSetBatcher(s, true);2226 let helper = filter({batcher, fn: (i) => i < 4 })2227 expect(helper).toEqual({2228 /* Because was Mutated */2229 initialValue: new Set([1, 2, 3]),2230 mutateInitial: true,2231 cloneFn: cloneSet,2232 /* Because added 3 */2233 hasChanged: true,2234 /* Because Mutated */2235 currentValue: new Set([1, 2, 3])2236 })2237 /* Reference holds because mutated */2238 expect(helper.initialValue).toBe(s);2239 expect(helper.currentValue).toBe(s); 2240 expect(helper).toBe(batcher);2241 }) 2242 })2243 describe('unchanged', () => {2244 it ('does not change with mutate: true', () => {2245 const s = new Set<number>([1, 2, 3, 4, 5]);2246 let helper = filter({target: s, fn: (i) => i < 10, mutate: true})2247 expect(helper).toEqual({2248 /* Because did not change */2249 initialValue: new Set([1, 2, 3, 4, 5]),2250 mutateInitial: true,2251 cloneFn: cloneSet,2252 hasChanged: false,2253 /* Because did not change */2254 currentValue: new Set([1, 2, 3, 4, 5])2255 })2256 /* Reference holds because mutated */2257 expect(helper.initialValue).toBe(s);2258 expect(helper.currentValue).toBe(s); 2259 }) 2260 it ('does not change with batcher mutate', () => {2261 const s = new Set<number>([1, 2, 3, 4, 5]);2262 let batcher = useSetBatcher(s, true);2263 let helper = filter({target: s, fn: i => i < 10, batcher})2264 expect(helper).toEqual({2265 /* Because did not change */2266 initialValue: new Set([1, 2, 3, 4, 5]),2267 mutateInitial: true,2268 cloneFn: cloneSet,2269 hasChanged: false,2270 /* Because did not change */2271 currentValue: new Set([1, 2, 3, 4, 5])2272 })2273 /* Reference holds because mutated */2274 expect(helper.initialValue).toBe(s);2275 expect(helper.currentValue).toBe(s); 2276 expect(helper).toBe(batcher);2277 }) 2278 }) 2279 }) 2280 })2281 2282 describe('3 operations', () => {2283 describe('mutable', () => {2284 it('mutable changed, changed, changed', () => {2285 const s = new Set<number>([1, 2, 3, 4]);2286 let batcher = useSetBatcher(s, true);2287 let helper = filter({batcher, fn: i => i < 4})2288 expect(helper).toEqual({2289 /* Because was Mutated */2290 initialValue: new Set([1, 2, 3]),2291 mutateInitial: true,2292 cloneFn: cloneSet,2293 /* Because added 3 */2294 hasChanged: true,2295 /* Because Mutated */2296 currentValue: new Set([1, 2, 3])2297 })2298 /* Reference holds because mutated */2299 expect(helper.initialValue).toBe(s);2300 expect(helper.currentValue).toBe(s); 2301 2302 helper = filter({batcher: helper, fn: i => i < 3})2303 expect(helper).toEqual({2304 /* Because was Mutated */2305 initialValue: new Set([1, 2]),2306 mutateInitial: true,2307 cloneFn: cloneSet,2308 /* Because added 3 */2309 hasChanged: true,2310 /* Because Mutated */2311 currentValue: new Set([1, 2])2312 })2313 /* Reference holds because mutated */2314 expect(helper.initialValue).toBe(s);2315 expect(helper.currentValue).toBe(s); 2316 2317 helper = filter({batcher: helper, fn: i => i < 2})2318 expect(helper).toEqual({2319 /* Because was Mutated */2320 initialValue: new Set([1]),2321 mutateInitial: true,2322 cloneFn: cloneSet,2323 /* Because added 3 */2324 hasChanged: true,2325 /* Because Mutated */2326 currentValue: new Set([1])2327 })2328 /* Reference holds because mutated */2329 expect(helper.initialValue).toBe(s);2330 expect(helper.currentValue).toBe(s); 2331 })2332 2333 it('mutable changed, changed, not changed', () => {2334 const s = new Set<number>([1, 2, 3, 4]);2335 let batcher = useSetBatcher(s, true);2336 let helper = filter({batcher, fn: i => i < 4})2337 expect(helper).toEqual({2338 /* Because was Mutated */2339 initialValue: new Set([1, 2, 3]),2340 mutateInitial: true,2341 cloneFn: cloneSet,2342 /* Because added 3 */2343 hasChanged: true,2344 /* Because Mutated */2345 currentValue: new Set([1, 2, 3])2346 })2347 /* Reference holds because mutated */2348 expect(helper.initialValue).toBe(s);2349 expect(helper.currentValue).toBe(s); 2350 2351 helper = filter({batcher, fn: i => i < 3})2352 expect(helper).toEqual({2353 /* Because was Mutated */2354 initialValue: new Set([1, 2]),2355 mutateInitial: true,2356 cloneFn: cloneSet,2357 /* Because added 3 */2358 hasChanged: true,2359 /* Because Mutated */2360 currentValue: new Set([1, 2])2361 })2362 /* Reference holds because mutated */2363 expect(helper.initialValue).toBe(s);2364 expect(helper.currentValue).toBe(s); 2365 2366 helper = filter({batcher, fn: i => i < 10})2367 expect(helper).toEqual({2368 /* Because was Mutated */2369 initialValue: new Set([1, 2]),2370 mutateInitial: true,2371 cloneFn: cloneSet,2372 /* Because added 3 */2373 hasChanged: true,2374 /* Because Mutated */2375 currentValue: new Set([1, 2])2376 })2377 /* Reference holds because mutated */2378 expect(helper.initialValue).toBe(s);2379 expect(helper.currentValue).toBe(s); 2380 })2381 2382 it('mutable changed, not changed, changed', () => {2383 const s = new Set<number>([1, 2, 3, 4]);2384 let batcher = useSetBatcher(s, true);2385 let helper = filter({batcher, fn: (i) => i < 4})2386 expect(helper).toEqual({2387 /* Because was Mutated */2388 initialValue: new Set([1, 2, 3]),2389 mutateInitial: true,2390 cloneFn: cloneSet,2391 /* Because added 3 */2392 hasChanged: true,2393 /* Because Mutated */2394 currentValue: new Set([1, 2, 3])2395 })2396 /* Reference holds because mutated */2397 expect(helper.initialValue).toBe(s);2398 expect(helper.currentValue).toBe(s); 2399 2400 helper = filter({batcher: helper, fn: i => i < 10})2401 expect(helper).toEqual({2402 /* Because was Mutated */2403 initialValue: new Set([1, 2, 3]),2404 mutateInitial: true,2405 cloneFn: cloneSet,2406 /* Because added 3 */2407 hasChanged: true,2408 /* Because Mutated */2409 currentValue: new Set([1, 2, 3])2410 })2411 /* Reference holds because mutated */2412 expect(helper.initialValue).toBe(s);2413 expect(helper.currentValue).toBe(s); 2414 2415 helper = filter({batcher: helper, fn: i => i < 3})2416 expect(helper).toEqual({2417 /* Because was Mutated */2418 initialValue: new Set([1, 2]),2419 mutateInitial: true,2420 cloneFn: cloneSet,2421 /* Because added 3 */2422 hasChanged: true,2423 /* Because Mutated */2424 currentValue: new Set([1, 2])2425 })2426 /* Reference holds because mutated */2427 expect(helper.initialValue).toBe(s);2428 expect(helper.currentValue).toBe(s); 2429 })2430 2431 it('mutable changed, not changed, not changed', () => {2432 const s = new Set<number>([1, 2, 3, 4, 5]);2433 let batcher = useSetBatcher(s, true);2434 let helper = filter({batcher, fn: i => i < 4})2435 expect(helper).toEqual({2436 /* Because was Mutated */2437 initialValue: new Set([1, 2, 3]),2438 mutateInitial: true,2439 cloneFn: cloneSet,2440 /* Because added 3 */2441 hasChanged: true,2442 /* Because Mutated */2443 currentValue: new Set([1, 2, 3])2444 })2445 /* Reference holds because mutated */2446 expect(helper.initialValue).toBe(s);2447 expect(helper.currentValue).toBe(s); 2448 2449 helper = filter({batcher: helper, fn: i => i < 5})2450 expect(helper).toEqual({2451 /* Because was Mutated */2452 initialValue: new Set([1, 2, 3]),2453 mutateInitial: true,2454 cloneFn: cloneSet,2455 /* Because added 3 */2456 hasChanged: true,2457 /* Because Mutated */2458 currentValue: new Set([1, 2, 3])2459 })2460 /* Reference holds because mutated */2461 expect(helper.initialValue).toBe(s);2462 expect(helper.currentValue).toBe(s); 2463 2464 helper = filter({batcher: helper, fn: i => i < 6})2465 expect(helper).toEqual({2466 /* Because was Mutated */2467 initialValue: new Set([1, 2, 3]),2468 mutateInitial: true,2469 cloneFn: cloneSet,2470 /* Because added 3 */2471 hasChanged: true,2472 /* Because Mutated */2473 currentValue: new Set([1, 2, 3])2474 })2475 /* Reference holds because mutated */2476 expect(helper.initialValue).toBe(s);2477 expect(helper.currentValue).toBe(s); 2478 })2479 2480 it('mutable not changed, changed, changed', () => {2481 const s = new Set<number>([1, 2, 3, 4, 5]);2482 let batcher = useSetBatcher(s, true);2483 let helper = filter({batcher, fn: i => i < 6})2484 expect(helper).toEqual({2485 /* Because was Mutated */2486 initialValue: new Set([1, 2, 3, 4, 5]),2487 mutateInitial: true,2488 cloneFn: cloneSet,2489 /* Because added 3 */2490 hasChanged: false,2491 /* Because Mutated */2492 currentValue: new Set([1, 2, 3, 4, 5])2493 })2494 /* Reference holds because mutated */2495 expect(helper.initialValue).toBe(s);2496 expect(helper.currentValue).toBe(s); 2497 2498 helper = filter({batcher, fn: i => i < 5})2499 expect(helper).toEqual({2500 /* Because was Mutated */2501 initialValue: new Set([1, 2, 3, 4]),2502 mutateInitial: true,2503 cloneFn: cloneSet,2504 /* Because added 3 */2505 hasChanged: true,2506 /* Because Mutated */2507 currentValue: new Set([1, 2, 3, 4])2508 })2509 /* Reference holds because mutated */2510 expect(helper.initialValue).toBe(s);2511 expect(helper.currentValue).toBe(s); 2512 2513 helper = filter({batcher, fn: i => i < 4})2514 expect(helper).toEqual({2515 /* Because was Mutated */2516 initialValue: new Set([1, 2, 3]),2517 mutateInitial: true,2518 cloneFn: cloneSet,2519 /* Because added 3 */2520 hasChanged: true,2521 /* Because Mutated */2522 currentValue: new Set([1, 2, 3])2523 })2524 /* Reference holds because mutated */2525 expect(helper.initialValue).toBe(s);2526 expect(helper.currentValue).toBe(s); 2527 })2528 2529 it('mutable not changed, changed, not changed', () => {2530 const s = new Set<number>([1, 2]);2531 let batcher = useSetBatcher(s, true);2532 let helper = filter({batcher, fn: i => i < 4})2533 expect(helper).toEqual({2534 /* Because was Mutated */2535 initialValue: new Set([1, 2]),2536 mutateInitial: true,2537 cloneFn: cloneSet,2538 /* Because added 3 */2539 hasChanged: false,2540 /* Because Mutated */2541 currentValue: new Set([1, 2])2542 })2543 /* Reference holds because mutated */2544 expect(helper.initialValue).toBe(s);2545 expect(helper.currentValue).toBe(s); 2546 2547 helper = filter({batcher, fn: i => i < 2})2548 expect(helper).toEqual({2549 /* Because was Mutated */2550 initialValue: new Set([1]),2551 mutateInitial: true,2552 cloneFn: cloneSet,2553 /* Because added 3 */2554 hasChanged: true,2555 /* Because Mutated */2556 currentValue: new Set([1])2557 })2558 /* Reference holds because mutated */2559 expect(helper.initialValue).toBe(s);2560 expect(helper.currentValue).toBe(s); 2561 2562 helper = filter({batcher, fn: i => i < 5})2563 expect(helper).toEqual({2564 /* Because was Mutated */2565 initialValue: new Set([1]),2566 mutateInitial: true,2567 cloneFn: cloneSet,2568 /* Because added 3 */2569 hasChanged: true,2570 /* Because Mutated */2571 currentValue: new Set([1])2572 })2573 /* Reference holds because mutated */2574 expect(helper.initialValue).toBe(s);2575 expect(helper.currentValue).toBe(s); 2576 })2577 2578 it('mutable not changed, not changed, changed', () => {2579 const s = new Set<number>([1, 2]);2580 let batcher = useSetBatcher(s, true);2581 let helper = filter({batcher, fn: i => i < 5})2582 expect(helper).toEqual({2583 /* Because was Mutated */2584 initialValue: new Set([1, 2]),2585 mutateInitial: true,2586 cloneFn: cloneSet,2587 /* Because added 3 */2588 hasChanged: false,2589 /* Because Mutated */2590 currentValue: new Set([1, 2])2591 })2592 /* Reference holds because mutated */2593 expect(helper.initialValue).toBe(s);2594 expect(helper.currentValue).toBe(s); 2595 2596 helper = filter({batcher, fn: i => i < 3})2597 expect(helper).toEqual({2598 /* Because was Mutated */2599 initialValue: new Set([1, 2]),2600 mutateInitial: true,2601 cloneFn: cloneSet,2602 /* Because added 3 */2603 hasChanged: false,2604 /* Because Mutated */2605 currentValue: new Set([1, 2])2606 })2607 /* Reference holds because mutated */2608 expect(helper.initialValue).toBe(s);2609 expect(helper.currentValue).toBe(s); 2610 2611 helper = filter({batcher, fn: i => i < 2})2612 expect(helper).toEqual({2613 /* Because was Mutated */2614 initialValue: new Set([1]),2615 mutateInitial: true,2616 cloneFn: cloneSet,2617 /* Because added 3 */2618 hasChanged: true,2619 /* Because Mutated */2620 currentValue: new Set([1])2621 })2622 /* Reference holds because mutated */2623 expect(helper.initialValue).toBe(s);2624 expect(helper.currentValue).toBe(s); 2625 })2626 2627 it('mutable not changed, not changed, not changed', () => {2628 const s = new Set<number>([1, 2]);2629 let batcher = useSetBatcher(s, true);2630 let helper = filter({batcher, fn: i => i < 5})2631 expect(helper).toEqual({2632 /* Because was Mutated */2633 initialValue: new Set([1, 2]),2634 mutateInitial: true,2635 cloneFn: cloneSet,2636 /* Because added 3 */2637 hasChanged: false,2638 /* Because Mutated */2639 currentValue: new Set([1, 2])2640 })2641 /* Reference holds because mutated */2642 expect(helper.initialValue).toBe(s);2643 expect(helper.currentValue).toBe(s); 2644 2645 helper = filter({batcher, fn: i => i < 4})2646 expect(helper).toEqual({2647 /* Because was Mutated */2648 initialValue: new Set([1, 2]),2649 mutateInitial: true,2650 cloneFn: cloneSet,2651 /* Because added 3 */2652 hasChanged: false,2653 /* Because Mutated */2654 currentValue: new Set([1, 2])2655 })2656 /* Reference holds because mutated */2657 expect(helper.initialValue).toBe(s);2658 expect(helper.currentValue).toBe(s); 2659 2660 helper = filter({batcher, fn: i => i < 3})2661 expect(helper).toEqual({2662 /* Because was Mutated */2663 initialValue: new Set([1, 2]),2664 mutateInitial: true,2665 cloneFn: cloneSet,2666 /* Because added 3 */2667 hasChanged: false,2668 /* Because Mutated */2669 currentValue: new Set([1, 2])2670 })2671 /* Reference holds because mutated */2672 expect(helper.initialValue).toBe(s);2673 expect(helper.currentValue).toBe(s); 2674 })2675 })2676 2677 describe('immutable', () => {2678 it('immutable changed, changed, changed', () => {2679 const s = new Set<number>([1, 2, 3, 4, 5]);2680 let batcher = useSetBatcher(s);2681 let helper = filter({batcher, fn: i => i < 5})2682 expect(helper).toEqual({2683 /* Because was Mutated */2684 initialValue: new Set([1, 2, 3, 4, 5]),2685 mutateInitial: false,2686 cloneFn: cloneSet,2687 /* Because added 3 */2688 hasChanged: true,2689 /* Because Mutated */2690 currentValue: new Set([1, 2, 3, 4])2691 })2692 /* Reference holds because mutated */2693 expect(helper.initialValue).toBe(s);2694 expect(helper.currentValue).not.toBe(s); 2695 2696 let s1 = helper.currentValue;2697 2698 helper = filter({batcher, fn: i => i < 4})2699 expect(helper).toEqual({2700 /* Because was Mutated */2701 initialValue: new Set([1, 2, 3, 4, 5]),2702 mutateInitial: false,2703 cloneFn: cloneSet,2704 /* Because added 3 */2705 hasChanged: true,2706 /* Because Mutated */2707 currentValue: new Set([1, 2, 3])2708 })2709 /* Reference holds because mutated */2710 expect(helper.initialValue).toBe(s);2711 expect(helper.currentValue).not.toBe(s); 2712 expect(helper.currentValue).toBe(s1);2713 2714 helper = filter({batcher, fn: i => i < 3})2715 expect(helper).toEqual({2716 /* Because was Mutated */2717 initialValue: new Set([1, 2, 3, 4, 5]),2718 mutateInitial: false,2719 cloneFn: cloneSet,2720 /* Because added 3 */2721 hasChanged: true,2722 /* Because Mutated */2723 currentValue: new Set([1, 2])2724 })2725 /* Reference holds because mutated */2726 expect(helper.initialValue).toBe(s);2727 expect(helper.currentValue).not.toBe(s); 2728 expect(helper.currentValue).toBe(s1);2729 })2730 2731 it('immutable changed, changed, not changed', () => {2732 const s = new Set<number>([1, 2, 3, 4, 5]);2733 let batcher = useSetBatcher(s);2734 let helper = filter({batcher, fn: i => i < 5})2735 expect(helper).toEqual({2736 /* Because was Mutated */2737 initialValue: new Set([1, 2, 3, 4, 5]),2738 mutateInitial: false,2739 cloneFn: cloneSet,2740 /* Because added 3 */2741 hasChanged: true,2742 /* Because Mutated */2743 currentValue: new Set([1, 2, 3, 4])2744 })2745 /* Reference holds because mutated */2746 expect(helper.initialValue).toBe(s);2747 expect(helper.currentValue).not.toBe(s); 2748 2749 let s1 = helper.currentValue;2750 2751 helper = filter({batcher, fn: i => i < 4})2752 expect(helper).toEqual({2753 /* Because was Mutated */2754 initialValue: new Set([1, 2, 3, 4, 5]),2755 mutateInitial: false,2756 cloneFn: cloneSet,2757 /* Because added 3 */2758 hasChanged: true,2759 /* Because Mutated */2760 currentValue: new Set([1, 2, 3])2761 })2762 /* Reference holds because mutated */2763 expect(helper.initialValue).toBe(s);2764 expect(helper.currentValue).not.toBe(s); 2765 expect(helper.currentValue).toBe(s1);2766 2767 helper = filter({batcher, fn: i => i < 7})2768 expect(helper).toEqual({2769 /* Because was Mutated */2770 initialValue: new Set([1, 2, 3, 4, 5]),2771 mutateInitial: false,2772 cloneFn: cloneSet,2773 /* Because added 3 */2774 hasChanged: true,2775 /* Because Mutated */2776 currentValue: new Set([1, 2, 3])2777 })2778 /* Reference holds because mutated */2779 expect(helper.initialValue).toBe(s);2780 expect(helper.currentValue).not.toBe(s); 2781 expect(helper.currentValue).toBe(s1); 2782 })2783 2784 it('immutable changed, not changed, changed', () => {2785 const s = new Set<number>([1, 2, 3, 4, 5]);2786 let batcher = useSetBatcher(s);2787 let helper = filter({batcher, fn: i => i < 5})2788 expect(helper).toEqual({2789 /* Because was Mutated */2790 initialValue: new Set([1, 2, 3, 4, 5]),2791 mutateInitial: false,2792 cloneFn: cloneSet,2793 /* Because added 3 */2794 hasChanged: true,2795 /* Because Mutated */2796 currentValue: new Set([1, 2, 3, 4])2797 })2798 /* Reference holds because mutated */2799 expect(helper.initialValue).toBe(s);2800 expect(helper.currentValue).not.toBe(s); 2801 2802 let s1 = helper.currentValue;2803 2804 helper = filter({batcher, fn: i => i < 8})2805 expect(helper).toEqual({2806 /* Because was Mutated */2807 initialValue: new Set([1, 2, 3, 4, 5]),2808 mutateInitial: false,2809 cloneFn: cloneSet,2810 /* Because added 3 */2811 hasChanged: true,2812 /* Because Mutated */2813 currentValue: new Set([1, 2, 3, 4])2814 })2815 /* Reference holds because mutated */2816 expect(helper.initialValue).toBe(s);2817 expect(helper.currentValue).not.toBe(s); 2818 expect(helper.currentValue).toBe(s1);2819 2820 helper = filter({batcher, fn: i => i < 3})2821 expect(helper).toEqual({2822 /* Because was Mutated */2823 initialValue: new Set([1, 2, 3, 4, 5]),2824 mutateInitial: false,2825 cloneFn: cloneSet,2826 /* Because added 3 */2827 hasChanged: true,2828 /* Because Mutated */2829 currentValue: new Set([1, 2])2830 })2831 /* Reference holds because mutated */2832 expect(helper.initialValue).toBe(s);2833 expect(helper.currentValue).not.toBe(s); 2834 expect(helper.currentValue).toBe(s1); 2835 })2836 2837 it('immutable changed, not changed, not changed', () => {2838 const s = new Set<number>([1, 2, 3, 4, 5]);2839 let batcher = useSetBatcher(s);2840 let helper = filter({batcher, fn: i => i < 5})2841 expect(helper).toEqual({2842 /* Because was Mutated */2843 initialValue: new Set([1, 2, 3, 4, 5]),2844 mutateInitial: false,2845 cloneFn: cloneSet,2846 /* Because added 3 */2847 hasChanged: true,2848 /* Because Mutated */2849 currentValue: new Set([1, 2, 3, 4])2850 })2851 /* Reference holds because mutated */2852 expect(helper.initialValue).toBe(s);2853 expect(helper.currentValue).not.toBe(s); 2854 2855 let s1 = helper.currentValue;2856 2857 helper = filter({batcher, fn: i => i < 7})2858 expect(helper).toEqual({2859 /* Because was Mutated */2860 initialValue: new Set([1, 2, 3, 4, 5]),2861 mutateInitial: false,2862 cloneFn: cloneSet,2863 /* Because added 3 */2864 hasChanged: true,2865 /* Because Mutated */2866 currentValue: new Set([1, 2, 3, 4])2867 })2868 /* Reference holds because mutated */2869 expect(helper.initialValue).toBe(s);2870 expect(helper.currentValue).not.toBe(s); 2871 expect(helper.currentValue).toBe(s1);2872 2873 helper = filter({batcher, fn: i => i < 9})2874 expect(helper).toEqual({2875 /* Because was Mutated */2876 initialValue: new Set([1, 2, 3, 4, 5]),2877 mutateInitial: false,2878 cloneFn: cloneSet,2879 /* Because added 3 */2880 hasChanged: true,2881 /* Because Mutated */2882 currentValue: new Set([1, 2, 3, 4])2883 })2884 /* Reference holds because mutated */2885 expect(helper.initialValue).toBe(s);2886 expect(helper.currentValue).not.toBe(s); 2887 expect(helper.currentValue).toBe(s1); 2888 })2889 2890 it('immutable not changed, changed, changed', () => {2891 const s = new Set<number>([1, 2, 3, 4, 5]);2892 let batcher = useSetBatcher(s);2893 let helper = filter({batcher, fn: i => i < 7})2894 expect(helper).toEqual({2895 /* Because was Mutated */2896 initialValue: new Set([1, 2, 3, 4, 5]),2897 mutateInitial: false,2898 cloneFn: cloneSet,2899 /* Because added 3 */2900 hasChanged: false,2901 /* Because Mutated */2902 currentValue: new Set([1, 2, 3, 4, 5])2903 })2904 /* Reference holds because mutated */2905 expect(helper.initialValue).toBe(s);2906 expect(helper.currentValue).toBe(s); 2907 2908 helper = filter({batcher, fn: i => i < 5})2909 expect(helper).toEqual({2910 initialValue: new Set([1, 2, 3, 4, 5]),2911 mutateInitial: false,2912 cloneFn: cloneSet,2913 /* Because added 3 */2914 hasChanged: true,2915 /* Because Mutated */2916 currentValue: new Set([1, 2, 3, 4])2917 })2918 expect(helper.initialValue).toBe(s);2919 expect(helper.currentValue).not.toBe(s); 2920 2921 let s1 = helper.currentValue;2922 2923 helper = filter({batcher, fn: i => i < 3})2924 expect(helper).toEqual({2925 /* Because was Mutated */2926 initialValue: new Set([1, 2, 3, 4, 5]),2927 mutateInitial: false,2928 cloneFn: cloneSet,2929 /* Because added 3 */2930 hasChanged: true,2931 /* Because Mutated */2932 currentValue: new Set([1, 2])2933 })2934 /* Reference holds because mutated */2935 expect(helper.initialValue).toBe(s);2936 expect(helper.currentValue).not.toBe(s); 2937 expect(helper.currentValue).toBe(s1)2938 })2939 2940 it('immutable not changed, changed, not changed', () => {2941 const s = new Set<number>([1, 2, 3, 4, 5]);2942 let batcher = useSetBatcher(s);2943 let helper = filter({batcher, fn: i => i < 6})2944 expect(helper).toEqual({2945 /* Because was Mutated */2946 initialValue: new Set([1, 2, 3, 4, 5]),2947 mutateInitial: false,2948 cloneFn: cloneSet,2949 /* Because added 3 */2950 hasChanged: false,2951 /* Because Mutated */2952 currentValue: new Set([1, 2, 3, 4, 5])2953 })2954 /* Reference holds because mutated */2955 expect(helper.initialValue).toBe(s);2956 expect(helper.currentValue).toBe(s); 2957 2958 helper = filter({batcher, fn: i => i < 4})2959 expect(helper).toEqual({2960 initialValue: new Set([1, 2, 3, 4, 5]),2961 mutateInitial: false,2962 cloneFn: cloneSet,2963 /* Because added 3 */2964 hasChanged: true,2965 /* Because Mutated */2966 currentValue: new Set([1, 2, 3])2967 })2968 expect(helper.initialValue).toBe(s);2969 expect(helper.currentValue).not.toBe(s); 2970 2971 let s1 = helper.currentValue;2972 2973 helper = filter({batcher, fn: i => i < 7})2974 expect(helper).toEqual({2975 /* Because was Mutated */2976 initialValue: new Set([1, 2, 3, 4, 5]),2977 mutateInitial: false,2978 cloneFn: cloneSet,2979 /* Because added 3 */2980 hasChanged: true,2981 /* Because Mutated */2982 currentValue: new Set([1, 2, 3])2983 })2984 /* Reference holds because mutated */2985 expect(helper.initialValue).toBe(s);2986 expect(helper.currentValue).not.toBe(s); 2987 expect(helper.currentValue).toBe(s1) 2988 })2989 2990 it('immutable not changed, not changed, changed', () => {2991 const s = new Set<number>([1, 2, 3, 4, 5]);2992 let batcher = useSetBatcher(s);2993 let helper = filter({batcher, fn: i => i < 7})2994 expect(helper).toEqual({2995 /* Because was Mutated */2996 initialValue: new Set([1, 2, 3, 4, 5]),2997 mutateInitial: false,2998 cloneFn: cloneSet,2999 /* Because added 3 */3000 hasChanged: false,3001 /* Because Mutated */3002 currentValue: new Set([1, 2, 3, 4, 5])3003 })3004 /* Reference holds because mutated */3005 expect(helper.initialValue).toBe(s);3006 expect(helper.currentValue).toBe(s); 3007 3008 helper = filter({batcher, fn: i => i < 6})3009 expect(helper).toEqual({3010 initialValue: new Set([1, 2, 3, 4, 5]),3011 mutateInitial: false,3012 cloneFn: cloneSet,3013 /* Because added 3 */3014 hasChanged: false,3015 /* Because Mutated */3016 currentValue: new Set([1, 2, 3, 4, 5])3017 })3018 expect(helper.initialValue).toBe(s);3019 expect(helper.currentValue).toBe(s); 3020 3021 let s1 = helper.currentValue;3022 3023 helper = filter({batcher, fn: i => i < 4})3024 expect(helper).toEqual({3025 /* Because was Mutated */3026 initialValue: new Set([1, 2, 3, 4, 5]),3027 mutateInitial: false,3028 cloneFn: cloneSet,3029 /* Because added 3 */3030 hasChanged: true,3031 /* Because Mutated */3032 currentValue: new Set([1, 2, 3])3033 })3034 /* Reference holds because mutated */3035 expect(helper.initialValue).toBe(s);3036 expect(helper.currentValue).not.toBe(s); 3037 expect(helper.currentValue).not.toBe(s1); 3038 })3039 3040 it('immutable not changed, not changed, not changed', () => {3041 const s = new Set<number>([1, 2, 3, 4, 5]);3042 let batcher = useSetBatcher(s);3043 let helper = filter({batcher, fn: i => i < 8})3044 expect(helper).toEqual({3045 /* Because was Mutated */3046 initialValue: new Set([1, 2, 3, 4, 5]),3047 mutateInitial: false,3048 cloneFn: cloneSet,3049 /* Because added 3 */3050 hasChanged: false,3051 /* Because Mutated */3052 currentValue: new Set([1, 2, 3, 4, 5])3053 })3054 /* Reference holds because mutated */3055 expect(helper.initialValue).toBe(s);3056 expect(helper.currentValue).toBe(s); 3057 3058 helper = filter({batcher, fn: i => i < 6})3059 expect(helper).toEqual({3060 initialValue: new Set([1, 2, 3, 4, 5]),3061 mutateInitial: false,3062 cloneFn: cloneSet,3063 /* Because added 3 */3064 hasChanged: false,3065 /* Because Mutated */3066 currentValue: new Set([1, 2, 3, 4, 5])3067 })3068 expect(helper.initialValue).toBe(s);3069 expect(helper.currentValue).toBe(s); 3070 3071 let s1 = helper.currentValue;3072 3073 helper = filter({batcher, fn: i => i < 7})3074 expect(helper).toEqual({3075 /* Because was Mutated */3076 initialValue: new Set([1, 2, 3, 4, 5]),3077 mutateInitial: false,3078 cloneFn: cloneSet,3079 /* Because added 3 */3080 hasChanged: false,3081 /* Because Mutated */3082 currentValue: new Set([1, 2, 3, 4, 5])3083 })3084 /* Reference holds because mutated */3085 expect(helper.initialValue).toBe(s);3086 expect(helper.currentValue).toBe(s); 3087 expect(helper.currentValue).toBe(s1); 3088 })3089 })3090 })3091 3092 3093 })...

Full Screen

Full Screen

deepClone.js

Source:deepClone.js Github

copy

Full Screen

1/*2 * @Description: 实现一个深拷贝3 * @Autor: ycc4 * @Date: 2022-04-24 10:50:045 * @LastEditTime: 2022-04-25 20:55:166 *7 * 浅拷贝:两者共用一个内存地址,比如直接复制8 * 深拷贝:重新开辟了一块内存,将要拷贝的值放入其中9 * 很多方法都只实现了一层浅拷贝:比如...,Object.assign等10 * JSON.stringify的弊端:时间对象只是拷贝了字符串形式、function和undefined会丢失,正则会等到空对象等等11 */12// 获取精确类型13getType = (value) => {14 const s = Object.prototype.toString.call(value);15 // 取出最后的类型16 return s.replace(/^.+\s/, '').replace(']', '');17};18// 基础版本19const deepClone = (target, map = new Map()) => {20 // debugger21 // 防止循环引用,并且一定程度上做了缓存22 if (map.has(target)) {23 return map.get(target)24 }25 // 拷贝Object26 if (getType(target) === 'Object') {27 const cloneObj = {};28 map.set(target, cloneObj)29 Object.keys(target).forEach(key => {30 cloneObj[key] = deepClone(target[key], map)31 })32 return cloneObj;33 }34 // 拷贝Array35 if (Array.isArray(target)) {36 const cloneArr = [];37 map.set(target, cloneArr)38 const len = target.length;39 for (let i = 0; i < len; i++) {40 cloneArr[i] = deepClone(target[i], map);41 }42 return cloneArr;43 }44 // Function45 if (getType(target) === 'Function') {46 const cloneFun = new Function('return ' + target.toString()).call(this)47 map.set(target, cloneFun)48 return cloneFun49 }50 // Date51 if (getType(target) === 'Date') {52 const cloneDate = new Date(target.valueOf())53 map.set(target, cloneDate)54 return cloneFun55 }56 // RegExp57 if (getType(target) === 'RegExp') {58 const cloneRegExp = new RegExp(target)59 map.set(target, cloneRegExp)60 return cloneRegExp61 }62 // Set63 if (getType(target) === 'Set') {64 const cloneSet = new Set()65 map.set(target, cloneSet)66 for (const item of target.values()) {67 cloneSet.add(deepClone(item, map))68 }69 return cloneSet70 }71 // Map72 if (getType(target) === 'Map') {73 const cloneMap = new Map()74 map.set(target, cloneMap)75 for (const [key, value] of target.entries()) {76 cloneSet.set(key, deepClone(value, map))77 }78 return cloneMap79 }80 // 其他类型,不需要特殊处理的基本类型,直接返回81 map.set(target, target)82 return target83};84const cloneFun = function (fn) {85 return new Function('return ' + fn.toString()).call(this)86}87const getType = (value) => {88 const r = Object.prototype.toString.call(value)89 r.replace(/^.+\s/, '').replace(']', '')90}91const cloneDeep = (target, map = new Map()) => {92 // 解决循环引用问题,也有一定缓存的效果93 if (map.has(target)) {94 return map.get(target)95 }96 // Object97 if (getType(target) === 'Object') {98 const cloneObj = {}99 map.set(target, cloneObj)100 Object.keys(target).forEach(key => {101 cloneObj[key] = cloneDeep(target[key], map)102 })103 return cloneObj104 }105 // Array106 if (getType(target) === 'Array') {107 const cloneArr = []108 map.set(target, cloneArr)109 const len = target.length110 for (let i = 0; i < len; i++) {111 cloneArr[i] = cloneDeep(target[i], map)112 }113 return cloneArr114 }115 // Function116 if (getType(target) === 'Function') {117 const cloneFun = new Function('return ' + target.toString()).call(this)118 map.set(target, cloneFun)119 return cloneFun120 }121 //Date122 if (getType(target) === 'Date') {123 const cloneDate = new Date(target.valueOf())124 map.set(target, cloneDate)125 return cloneDate126 }127 //RegExp128 if (getType(target) === 'RegExp') {129 const cloneRegExp = new RegExp(target)130 map.set(target, cloneRegExp)131 return cloneRegExp132 }133 // Map134 if (getType(target) === 'Map') {135 const cloneMap = new Map()136 map.set(target, cloneMap)137 for (const [key, value] of cloneMap.entries()) {138 cloneMap.set(key, cloneDeep(value, map))139 }140 return cloneRegExp141 }142 // Set143 if (getType(target) === 'Map') {144 const cloneSet = new Set()145 map.set(target, cloneSet)146 for (const value of cloneSet.values()) {147 cloneSet.add(cloneDeep(value, map))148 }149 return cloneSet150 }151 //其他类型,为基本类型,不需要特殊处理,直接返回target即可,函数传参时已经深拷贝了一份152 map.set(target, target)153 return target154}155function testDeepClone() {156 const obj = {157 a: 1,158 b: '2',159 c: undefined,160 d: null,161 e: {162 e1: 'e1',163 },164 f: ['f1'],165 g() {166 console.log(this, 'this');167 },168 };169 obj.x = obj;170 const obj2 = deepClone(obj);...

Full Screen

Full Screen

SetOps.js

Source:SetOps.js Github

copy

Full Screen

1function cloneSet(set0) {2 let ret = new Set();3 set0.forEach(i => {4 ret.add(i);5 })6 return ret;7}8function getUnion(set1, set2) {9 let ret = cloneSet(set1);10 set2.forEach(i => {11 ret.add(i);12 });13 return ret;14}15function getDiff (set1, set2) {16 let ret = cloneSet(set1);17 set2.forEach(i => {18 ret.delete(i);19 });20 return ret;21}22function getSymDiff(set1, set2) {23 let diff1 = getDiff(set1, set2);24 let diff2 = getDiff(set2, set1);25 return getUnion(diff1, diff2);26}27function getIts (set1, set2) {28 let ret = cloneSet(set1);29 set2.forEach(i => {30 if(set1.has(i)) {31 ret.add(i);32 }33 });34 return ret;35}36let a = new Set([1,2,3,4,5,6]);37let b = new Set([4,5,6,7,8,9]);38console.log('getUnion: ', getUnion(a,b));39console.log('getDiff: ', getDiff(a,b));40console.log('getDiff: ', getDiff(b,a));41console.log('getSymDiff: ', getSymDiff(a, b));42console.log('getIts: ', getIts(a,b));

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var cloneSet = ladle.cloneSet;3var set1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];4var set2 = cloneSet(set1);5console.log(set1);6console.log(set2);7var ladle = require('ladle');8var cloneSet = ladle.cloneSet;9var set1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];10var set2 = cloneSet(set1);11console.log(set1);12console.log(set2);13var ladle = require('ladle');14var cloneSet = ladle.cloneSet;15var set1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];16var set2 = cloneSet(set1);17console.log(set1);18console.log(set2);19var ladle = require('ladle');20var cloneSet = ladle.cloneSet;

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require("./ladle.js");2var set = new ladle.Set();3set.add(1);4set.add(2);5set.add(3);6var set2 = set.cloneSet();7set2.add(4);8console.log("Set 1: " + set.toString());9console.log("Set 2: " + set2.toString());

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var set = ladle.set;3var cloneSet = ladle.cloneSet;4var set1 = new set([1,2,3,4]);5var set2 = cloneSet(set1);6set1.add(5);7var ladle = require('ladle');8var set = ladle.set;9var cloneSet = ladle.cloneSet;10var set1 = new set([1,2,3,4]);11var set2 = cloneSet(set1);12set1.add(5);13var ladle = require('ladle');14var set = ladle.set;15var cloneSet = ladle.cloneSet;16var set1 = new set([1,2,3,4]);17var set2 = cloneSet(set1);18set1.add(5);19var ladle = require('ladle');20var set = ladle.set;21var cloneSet = ladle.cloneSet;22var set1 = new set([1,2,3,4]);23var set2 = cloneSet(set1);24set1.add(5);25var ladle = require('ladle');26var set = ladle.set;27var cloneSet = ladle.cloneSet;28var set1 = new set([1,2,3,

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var cloneSet = ladle.cloneSet;3var set = new ladle.Set();4set.add('a');5set.add('b');6set.add('c');7var clone = cloneSet(set);8console.log(clone);9var ladle = require('ladle');10var cloneMap = ladle.cloneMap;11var map = new ladle.Map();12map.set('a', 1);13map.set('b', 2);14map.set('c', 3);15var clone = cloneMap(map);16console.log(clone);17var ladle = require('ladle');18var cloneList = ladle.cloneList;19var list = new ladle.List();20list.add('a');21list.add('b');22list.add('c');23var clone = cloneList(list);24console.log(clone);25var ladle = require('ladle');26var cloneCollection = ladle.cloneCollection;27var collection = new ladle.Collection();28collection.add('a');29collection.add('b');30collection.add('c');31var clone = cloneCollection(collection);32console.log(clone);33var ladle = require('ladle');34var clone = ladle.clone;35var collection = new ladle.Collection();36collection.add('a');37collection.add('b');38collection.add('c');39var clone = clone(collection);40console.log(clone);41var ladle = require('ladle');42var clone = ladle.clone;43var collection = new ladle.Collection();44collection.add('a');45collection.add('b');46collection.add('c');47var clone = clone(collection);48console.log(clone);

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var set = ladle.createSet();3set.add(1);4set.add(2);5set.add(3);6var set2 = set.cloneSet();7console.log(set2);8var ladle = require('ladle');9var set = ladle.createSet();10set.add(1);11set.add(2);12set.add(3);13console.log(set);14var ladle = require('ladle');15var set = ladle.createSet();16set.add(1);17set.add(2);18set.add(3);19set.remove(2);20console.log(set);21var ladle = require('ladle');22var set = ladle.createSet();23set.add(1);24set.add(2);25set.add(3);26set.remove(2);27console.log(set);28var ladle = require('ladle');29var set = ladle.createSet();30set.add(1);31set.add(2);32set.add(3);33console.log(set.has(2));34var ladle = require('ladle');35var set = ladle.createSet();36set.add(1);37set.add(2);38set.add(3);39console.log(set.size());40var ladle = require('ladle');41var set = ladle.createSet();42set.add(1);43set.add(2);44set.add(3);45console.log(set.values());46var ladle = require('ladle');

Full Screen

Using AI Code Generation

copy

Full Screen

1var Ladle = require('ladle');2var ladle = new Ladle({host: 'localhost', port: 27017});3ladle.cloneSet('test', 'test2', function(err, result) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(result);9 }10});11{ ok: 1, fromdb: 'test', todb: 'test2' }12var Ladle = require('ladle');13var ladle = new Ladle({host: 'localhost', port: 27017});14ladle.cloneDatabase('test', 'test2', function(err, result) {15 if (err) {16 console.log(err);17 }18 else {19 console.log(result);20 }21});22{ ok: 1, fromdb: 'test', todb: 'test2' }23var Ladle = require('ladle');24var ladle = new Ladle({host: 'localhost', port: 27017});25ladle.cloneCollection('test', 'testCollection', 'testCollection2', function(err, result) {26 if (err) {27 console.log(err);28 }29 else {30 console.log(result);31 }32});33{ ok: 1, fromdb: 'test', fromcollection: 'testCollection', todb: 'test', tocollection: 'testCollection2' }34var Ladle = require('ladle

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var set = new ladle.Set();3set.add('a');4set.add('b');5set.add('c');6var clone = set.cloneSet();7var ladle = require('ladle');8var set = new ladle.Set();9set.add('a');10set.add('b');11set.add('c');12var clone = set.cloneSet();

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var set = ladle.cloneSet(['item1', 'item2', 'item3']);3console.log(set);4var ladle = require('ladle');5var set = ladle.cloneSet(['item1', 'item2', 'item3']);6console.log(set);7var ladle = require('ladle');8var set = ladle.cloneSet(['item1', 'item2', 'item3']);9console.log(set);10var ladle = require('ladle');11var set = ladle.cloneSet(['item1', 'item2', 'item3']);12console.log(set);13var ladle = require('ladle');14var set = ladle.cloneSet(['item1', 'item2', 'item3']);15console.log(set);16var ladle = require('ladle');17var set = ladle.cloneSet(['item1', 'item2', 'item3']);18console.log(set);19var ladle = require('ladle');20var set = ladle.cloneSet(['item1', 'item2', 'item3']);21console.log(set);22var ladle = require('ladle');23var set = ladle.cloneSet(['item1', 'item2', 'item3']);24console.log(set);25var ladle = require('ladle');26var set = ladle.cloneSet(['item1', 'item2', 'item3']);27console.log(set);28var ladle = require('ladle');29var set = ladle.cloneSet(['item1', 'item2', 'item3']);30console.log(set);31var ladle = require('ladle

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2console.log(set.get());3var ladle = require('ladle');4console.log(set.get());5var ladle = require('ladle');6console.log(set.get());7var ladle = require('ladle');8console.log(set.get());9var ladle = require('ladle');10console.log(set.get());11var ladle = require('ladle');

Full Screen

Using AI Code Generation

copy

Full Screen

1var ladle = require('ladle');2var source = {a: 1, b: 2, c: 3};3var destination = {a: 2, c: 3, d: 4};4ladle.cloneSet(source, destination);5var ladle = require('ladle');6var source = {a: 1, b: 2, c: 3};7var destination = {a: 2, c: 3, d: 4};8ladle.cloneSet(source, destination);9var ladle = require('ladle');10var source = {a: 1, b: 2, c: 3};11var destination = {a: 2, c: 3, d: 4};12ladle.cloneSet(source, destination);13var ladle = require('ladle');14var source = {a: 1, b: 2, c: 3};15var destination = {a: 2, c: 3, d: 4};16ladle.cloneSet(source, destination);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ladle automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful