@@ -566,21 +566,88 @@ export interface CollectConfigInterface<DataType = any> {
566
566
567
567
<br />
568
568
569
- #### ` key `
569
+ #### ` patch `
570
570
571
- Key/Name of Selector.
571
+ Under the hood it calls the [ ` patch ` ] ( ./packages/core/features/state/Methods.md#patch ) method
572
+ instead of the [ ` set ` ] ( ./packages/core/features/state/Methods.md#set ) method.
573
+ Of course, it is only useful if we patch something into something existing,
574
+ what shouldn't be the case in the ` collect ` method.
572
575
573
576
| Type | Default | Required |
574
577
| --------------------------| -----------| ----------|
575
- | ` string \| name ` | undefined | No |
578
+ | ` boolean ` | false | No |
579
+
580
+ <br />
581
+
582
+ #### ` method `
583
+
584
+ In which way the collected data primary Key gets added to the Groups.
585
+ By using ` push ` it will be added at the end of the primaryKey array
586
+ ``` ts {2}
587
+ MY_COLLECTION .collect ({id: 1 , name: " jeff" }, {method: ' push' });
588
+ MY_COLLECTION .getGroup (MY_COLLECTION .config .defaultGroupKey ).value ; // Returns [5, 6, 0, 1]
589
+ ```
590
+ and by ` unshift ` it can be found at the beginning of the primaryKey array.
591
+ ``` ts {2}
592
+ MY_COLLECTION .collect ({id: 8 , name: " jeff" }, {method: ' unshift' });
593
+ MY_COLLECTION .getGroup (MY_COLLECTION .config .defaultGroupKey ).value ; // Returns [8, 5, 6, 0, 1]
594
+ ```
595
+
596
+ | Type | Default | Required |
597
+ | --------------------------| -----------| ----------|
598
+ | ` push' \| 'unshift' ` | 'push' | No |
599
+
600
+ <br />
601
+
602
+ #### ` forEachItem `
603
+
604
+ Gets called for each collected Data.
605
+ ``` ts {4-9}
606
+ MY_COLLECTION .collect ([
607
+ {id: 1 , name: " jeff" },
608
+ {id: 8 , name: " frank" }],
609
+ {forEachItem : (data , key , index ) => {
610
+ // Gets Called with data: {id: 1, name: "jeff"}, key: 1, index: 0
611
+ // and
612
+ // Gets Called with data: {id: 2, name: "frank"}, key: 8, index: 1
613
+ }
614
+ })
615
+ ```
616
+
617
+ | Type | Default | Required |
618
+ | -------------------------------------------------------------| -----------| ----------|
619
+ | ` (data: DataType, key: ItemKey, index: number) => void ` | undefined | No |
576
620
577
621
<br />
578
622
623
+ #### ` background `
579
624
580
- | Prop | Type | Default | Description | Required |
581
- | -------------------| --------------------------| -------------| -------------------------------------------------------------------------------------------------------------------------| ----------|
582
- | patch | boolean | false | Key/Name of Selector | No |
583
- | method | push' \| 'unshift' | 'push' | If Selector is initially a Placeholder | No |
584
- | forEachItem | boolean | false | If Selector is initially a Placeholder | No |
585
- | background | boolean | false | If Selector is initially a Placeholder | No |
586
- | select | boolean | false | If Selector is initially a Placeholder | No |
625
+ Sometimes we want to add new data to our Collection in background,
626
+ so that no component rerender that has bound the Collection to itself.
627
+ Then this property might get handy.
628
+ ``` ts {5}
629
+ // Causes rerender on Components
630
+ MY_COLLECTION .collect ({id: 1 , name: " jeff" });
631
+
632
+ // Doesn't cause rerender on Comonents
633
+ MY_COLLECTION .collect ({id: 1 , name: " jeff" }, {background: true });
634
+ ```
635
+
636
+ | Type | Default | Required |
637
+ | --------------------------| -----------| ----------|
638
+ | ` boolean ` | false | No |
639
+
640
+ <br />
641
+
642
+ #### ` select `
643
+
644
+ If foreach collected Data a [ Selector] ( ./packages/core/features/collection/selector/Introduction.md ) gets created,
645
+ which is a separate State that represents the Data Value.
646
+ ``` ts {5}
647
+ MY_COLLECTION .collect ({id: 1 , name: " jeff" }, {select: true });
648
+ MY_COLLECTION .getSelector (1 ); // Returns Selector that got just created
649
+ ```
650
+
651
+ | Type | Default | Required |
652
+ | --------------------------| -----------| ----------|
653
+ | ` boolean ` | false | No |
0 commit comments