@@ -728,9 +728,9 @@ describe(`Proxy Library`, () => {
728
728
const objs = [ { items : [ `apple` , `banana` , `cherry` ] } ]
729
729
const { proxies, getChanges } = createArrayChangeProxy ( objs )
730
730
731
- // Create a new array without the last element
731
+ // Call pop() method directly
732
732
// @ts -expect-error ok possibly undefined
733
- proxies [ 0 ] . items = proxies [ 0 ] . items . slice ( 0 , - 1 )
733
+ proxies [ 0 ] . items . pop ( )
734
734
735
735
expect ( getChanges ( ) ) . toEqual ( [
736
736
{
@@ -745,10 +745,9 @@ describe(`Proxy Library`, () => {
745
745
const objs = [ { items : [ `apple` , `banana` , `cherry` ] } ]
746
746
const { proxies, getChanges } = createArrayChangeProxy ( objs )
747
747
748
- // Create a new array without the first element
749
-
748
+ // Call shift() method directly
750
749
// @ts -expect-error ok possibly undefined
751
- proxies [ 0 ] . items = proxies [ 0 ] . items . slice ( 1 )
750
+ proxies [ 0 ] . items . shift ( )
752
751
753
752
expect ( getChanges ( ) ) . toEqual ( [
754
753
{
@@ -763,33 +762,38 @@ describe(`Proxy Library`, () => {
763
762
const objs = [ { items : [ `banana` , `cherry` ] } ]
764
763
const { proxies, getChanges } = createArrayChangeProxy ( objs )
765
764
766
- // Create a new array with an element added at the beginning
765
+ // Call unshift() method directly
767
766
// @ts -expect-error ok possibly undefined
768
-
769
- proxies [ 0 ] . items = [ `apple` , ...proxies [ 0 ] . items ]
767
+ proxies [ 0 ] . items . unshift ( `apple` )
770
768
771
769
expect ( getChanges ( ) ) . toEqual ( [
772
770
{
773
771
items : [ `apple` , `banana` , `cherry` ] ,
774
772
} ,
775
773
] )
776
774
// @ts -expect-error ok possibly undefined
777
-
778
775
expect ( objs [ 0 ] . items ) . toEqual ( [ `banana` , `cherry` ] )
779
776
} )
780
777
778
+ it ( `should track array push() operations` , ( ) => {
779
+ const obj = { items : [ `apple` , `banana` ] }
780
+ const { proxy, getChanges } = createChangeProxy ( obj )
781
+
782
+ proxy . items . push ( `cherry` )
783
+
784
+ expect ( getChanges ( ) ) . toEqual ( {
785
+ items : [ `apple` , `banana` , `cherry` ] ,
786
+ } )
787
+ expect ( obj . items ) . toEqual ( [ `apple` , `banana` ] )
788
+ } )
789
+
781
790
it ( `should track array splice() operations` , ( ) => {
782
791
const objs = [ { items : [ `apple` , `banana` , `cherry` , `date` ] } ]
783
792
const { proxies, getChanges } = createArrayChangeProxy ( objs )
784
793
785
- // Create a new array with elements replaced in the middle
786
- // @ts -expect-error ok possibly undefined
787
-
788
- const newItems = [ ...proxies [ 0 ] . items ]
789
- newItems . splice ( 1 , 2 , `blueberry` , `cranberry` )
794
+ // Call splice() method directly
790
795
// @ts -expect-error ok possibly undefined
791
-
792
- proxies [ 0 ] . items = newItems
796
+ proxies [ 0 ] . items . splice ( 1 , 2 , `blueberry` , `cranberry` )
793
797
794
798
expect ( getChanges ( ) ) . toEqual ( [
795
799
{
@@ -804,9 +808,9 @@ describe(`Proxy Library`, () => {
804
808
const objs = [ { items : [ `cherry` , `apple` , `banana` ] } ]
805
809
const { proxies, getChanges } = createArrayChangeProxy ( objs )
806
810
807
- // Create a new sorted array
811
+ // Call sort() method directly
808
812
// @ts -expect-error ok possibly undefined
809
- proxies [ 0 ] . items = [ ... proxies [ 0 ] . items ] . sort ( )
813
+ proxies [ 0 ] . items . sort ( )
810
814
811
815
expect ( getChanges ( ) ) . toEqual ( [
812
816
{
@@ -817,6 +821,65 @@ describe(`Proxy Library`, () => {
817
821
expect ( objs [ 0 ] . items ) . toEqual ( [ `cherry` , `apple` , `banana` ] )
818
822
} )
819
823
824
+ it ( `should track array reverse() operations` , ( ) => {
825
+ const objs = [ { items : [ `apple` , `banana` , `cherry` ] } ]
826
+ const { proxies, getChanges } = createArrayChangeProxy ( objs )
827
+
828
+ // Call reverse() method directly
829
+ // @ts -expect-error ok possibly undefined
830
+ proxies [ 0 ] . items . reverse ( )
831
+
832
+ expect ( getChanges ( ) ) . toEqual ( [
833
+ {
834
+ items : [ `cherry` , `banana` , `apple` ] ,
835
+ } ,
836
+ ] )
837
+ // @ts -expect-error ok possibly undefined
838
+ expect ( objs [ 0 ] . items ) . toEqual ( [ `apple` , `banana` , `cherry` ] )
839
+ } )
840
+
841
+ it ( `should track array fill() operations` , ( ) => {
842
+ const objs = [ { items : [ `apple` , `banana` , `cherry` ] } ]
843
+ const { proxies, getChanges } = createArrayChangeProxy ( objs )
844
+
845
+ // Call fill() method directly
846
+ // @ts -expect-error ok possibly undefined
847
+ proxies [ 0 ] . items . fill ( `orange` , 1 , 3 )
848
+
849
+ expect ( getChanges ( ) ) . toEqual ( [
850
+ {
851
+ items : [ `apple` , `orange` , `orange` ] ,
852
+ } ,
853
+ ] )
854
+ // @ts -expect-error ok possibly undefined
855
+ expect ( objs [ 0 ] . items ) . toEqual ( [ `apple` , `banana` , `cherry` ] )
856
+ } )
857
+
858
+ it ( `should track array copyWithin() operations` , ( ) => {
859
+ const objs = [
860
+ { items : [ `apple` , `banana` , `cherry` , `date` , `elderberry` ] } ,
861
+ ]
862
+ const { proxies, getChanges } = createArrayChangeProxy ( objs )
863
+
864
+ // Call copyWithin() method directly - copy elements from index 3-4 to index 0-1
865
+ // @ts -expect-error ok possibly undefined
866
+ proxies [ 0 ] . items . copyWithin ( 0 , 3 , 5 )
867
+
868
+ expect ( getChanges ( ) ) . toEqual ( [
869
+ {
870
+ items : [ `date` , `elderberry` , `cherry` , `date` , `elderberry` ] ,
871
+ } ,
872
+ ] )
873
+ // @ts -expect-error ok possibly undefined
874
+ expect ( objs [ 0 ] . items ) . toEqual ( [
875
+ `apple` ,
876
+ `banana` ,
877
+ `cherry` ,
878
+ `date` ,
879
+ `elderberry` ,
880
+ ] )
881
+ } )
882
+
820
883
it ( `should track changes in multi-dimensional arrays` , ( ) => {
821
884
const objs = [
822
885
{
0 commit comments