@quenty/observablecollection 12.55.0 → 12.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,21 +5,19 @@
5
5
 
6
6
  local require = require(script.Parent.loader).load(script)
7
7
 
8
- local Brio = require("Brio")
9
8
  local Jest = require("Jest")
10
9
  local Maid = require("Maid")
11
10
  local ObservableSortedList = require("ObservableSortedList")
11
+ local ObservableSpy = require("ObservableSpy")
12
12
  local ObservableSubscriptionTable = require("ObservableSubscriptionTable")
13
13
  local Rx = require("Rx")
14
- local Symbol = require("Symbol")
14
+ local SignalTestUtils = require("SignalTestUtils")
15
15
  local ValueObject = require("ValueObject")
16
16
 
17
17
  local describe = Jest.Globals.describe
18
18
  local expect = Jest.Globals.expect
19
19
  local it = Jest.Globals.it
20
20
 
21
- local NIL_VALUE = Symbol.named("nil_placeholder")
22
-
23
21
  local ObservableSortedListTestUtils = {}
24
22
 
25
23
  function ObservableSortedListTestUtils.fromList<string>(list: { string }): ObservableSortedList.ObservableSortedList<string>
@@ -32,18 +30,6 @@ function ObservableSortedListTestUtils.fromList<string>(list: { string }): Obser
32
30
  return sortedList
33
31
  end
34
32
 
35
- function ObservableSortedListTestUtils.collectValues(observable: any)
36
- local values = {}
37
- local sub = observable:Subscribe(function(value: any)
38
- if value == nil then
39
- table.insert(values, NIL_VALUE)
40
- else
41
- table.insert(values, value)
42
- end
43
- end)
44
- return values, sub
45
- end
46
-
47
33
  describe("ObservableSortedList", function()
48
34
  describe("Add", function()
49
35
  it("should insert a value synchronously", function()
@@ -198,7 +184,7 @@ describe("ObservableSortedList", function()
198
184
  local maid = Maid.new()
199
185
  local list = maid:Add(ObservableSortedList.new())
200
186
 
201
- local seenCounts, sub = ObservableSortedListTestUtils.collectValues(list:ObserveCount())
187
+ local seenCounts = ObservableSpy.new(list:ObserveCount())
202
188
 
203
189
  local removeA = list:Add("a", 1)
204
190
  list:_testForceFireEvents()
@@ -209,7 +195,7 @@ describe("ObservableSortedList", function()
209
195
  removeA()
210
196
  list:_testForceFireEvents()
211
197
 
212
- sub:Destroy()
198
+ seenCounts:Destroy()
213
199
 
214
200
  expect(seenCounts[1]).toEqual(0)
215
201
  expect(seenCounts[2]).toEqual(1)
@@ -228,7 +214,7 @@ describe("ObservableSortedList", function()
228
214
  list:Add("c", 3)
229
215
  list:_testForceFireEvents()
230
216
 
231
- local seenIndices, sub = ObservableSortedListTestUtils.collectValues(list:ObserveIndex(3))
217
+ local seenIndices = ObservableSpy.new(list:ObserveIndex(3))
232
218
 
233
219
  expect(#seenIndices).toEqual(1)
234
220
  expect(seenIndices[1]).toEqual(3)
@@ -236,7 +222,7 @@ describe("ObservableSortedList", function()
236
222
  removeB()
237
223
  list:_testForceFireEvents()
238
224
 
239
- sub:Destroy()
225
+ seenIndices:Destroy()
240
226
 
241
227
  expect(#seenIndices).toEqual(2)
242
228
  expect(seenIndices[2]).toEqual(2)
@@ -255,7 +241,7 @@ describe("ObservableSortedList", function()
255
241
 
256
242
  expect(list:GetCount()).toEqual(5)
257
243
 
258
- local seenIndicesForE, sub = ObservableSortedListTestUtils.collectValues(list:ObserveIndex(5))
244
+ local seenIndicesForE = ObservableSpy.new(list:ObserveIndex(5))
259
245
 
260
246
  expect(#seenIndicesForE).toEqual(1)
261
247
  expect(seenIndicesForE[1]).toEqual(5)
@@ -269,7 +255,7 @@ describe("ObservableSortedList", function()
269
255
  expect(#seenIndicesForE).toEqual(2)
270
256
  expect(seenIndicesForE[2]).toEqual(4)
271
257
 
272
- sub:Destroy()
258
+ seenIndicesForE:Destroy()
273
259
  maid:Destroy()
274
260
  end)
275
261
  end)
@@ -283,7 +269,7 @@ describe("ObservableSortedList", function()
283
269
  list:Add("c", 3)
284
270
  list:_testForceFireEvents()
285
271
 
286
- local seenItems, sub = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
272
+ local seenItems = ObservableSpy.new(list:ObserveAtIndex(2))
287
273
 
288
274
  expect(#seenItems).toEqual(1)
289
275
  expect(seenItems[1]).toEqual("b")
@@ -291,7 +277,7 @@ describe("ObservableSortedList", function()
291
277
  removeB()
292
278
  list:_testForceFireEvents()
293
279
 
294
- sub:Destroy()
280
+ seenItems:Destroy()
295
281
 
296
282
  expect(#seenItems).toEqual(2)
297
283
  expect(seenItems[2]).toEqual("c")
@@ -305,7 +291,7 @@ describe("ObservableSortedList", function()
305
291
  local list = maid:Add(ObservableSortedListTestUtils.fromList({ "a", "b" }))
306
292
  list:_testForceFireEvents()
307
293
 
308
- local seenBrios, sub = ObservableSortedListTestUtils.collectValues(list:ObserveItemsBrio())
294
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
309
295
 
310
296
  expect(#seenBrios).toEqual(2)
311
297
 
@@ -314,7 +300,7 @@ describe("ObservableSortedList", function()
314
300
 
315
301
  expect(#seenBrios).toEqual(3)
316
302
 
317
- sub:Destroy()
303
+ seenBrios:Destroy()
318
304
  maid:Destroy()
319
305
  end)
320
306
 
@@ -325,10 +311,7 @@ describe("ObservableSortedList", function()
325
311
  local removeA = list:Add("a", 1)
326
312
  list:_testForceFireEvents()
327
313
 
328
- local seenBrios: { Brio.Brio<string, any> } = {}
329
- local sub = list:ObserveItemsBrio():Subscribe(function(brio)
330
- table.insert(seenBrios, brio)
331
- end)
314
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
332
315
 
333
316
  expect(#seenBrios).toEqual(1)
334
317
  expect(seenBrios[1]:IsDead()).toEqual(false)
@@ -338,7 +321,7 @@ describe("ObservableSortedList", function()
338
321
 
339
322
  expect(seenBrios[1]:IsDead()).toEqual(true)
340
323
 
341
- sub:Destroy()
324
+ seenBrios:Destroy()
342
325
  maid:Destroy()
343
326
  end)
344
327
  end)
@@ -363,10 +346,7 @@ describe("ObservableSortedList", function()
363
346
  local maid = Maid.new()
364
347
  local list = maid:Add(ObservableSortedList.new())
365
348
 
366
- local seen: { { string } } = {}
367
- local sub = list:Observe():Subscribe(function(items)
368
- table.insert(seen, items)
369
- end)
349
+ local seen = ObservableSpy.new(list:Observe())
370
350
 
371
351
  list:Add("b", 2)
372
352
  list:_testForceFireEvents()
@@ -374,7 +354,7 @@ describe("ObservableSortedList", function()
374
354
  list:Add("a", 1)
375
355
  list:_testForceFireEvents()
376
356
 
377
- sub:Destroy()
357
+ seen:Destroy()
378
358
 
379
359
  expect(#seen).toEqual(3)
380
360
  expect(#seen[1]).toEqual(0)
@@ -456,12 +436,12 @@ describe("ObservableSortedList", function()
456
436
  local node = list:FindFirstKey("c")
457
437
  assert(node ~= nil, "Expected to find node for 'c'")
458
438
 
459
- local seenIndices, sub = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(node))
439
+ local seenIndices = ObservableSpy.new(list:ObserveIndexByKey(node))
460
440
 
461
441
  expect(#seenIndices).toEqual(1)
462
442
  expect(seenIndices[1]).toEqual(3)
463
443
 
464
- sub:Destroy()
444
+ seenIndices:Destroy()
465
445
  maid:Destroy()
466
446
  end)
467
447
  end)
@@ -482,7 +462,7 @@ describe("ObservableSortedList", function()
482
462
  local list = maid:Add(ObservableSortedListTestUtils.fromList({ "a", "b" }))
483
463
  list:_testForceFireEvents()
484
464
 
485
- local seenBrios, sub = ObservableSortedListTestUtils.collectValues(list:ObserveItemsBrio())
465
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
486
466
 
487
467
  expect(#seenBrios).toEqual(2)
488
468
  expect(seenBrios[1]:IsDead()).toEqual(false)
@@ -492,7 +472,7 @@ describe("ObservableSortedList", function()
492
472
 
493
473
  expect(seenBrios[1]:IsDead()).toEqual(true)
494
474
  expect(seenBrios[2]:IsDead()).toEqual(true)
495
- sub:Destroy()
475
+ seenBrios:Destroy()
496
476
  end)
497
477
  end)
498
478
 
@@ -591,7 +571,7 @@ describe("ObservableSortedList", function()
591
571
  list:Add("b", 2)
592
572
  list:_testForceFireEvents()
593
573
 
594
- local seenItems, sub = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
574
+ local seenItems = ObservableSpy.new(list:ObserveAtIndex(2))
595
575
 
596
576
  expect(#seenItems).toEqual(1)
597
577
  expect(seenItems[1]).toEqual("b")
@@ -599,10 +579,10 @@ describe("ObservableSortedList", function()
599
579
  removeA()
600
580
  list:_testForceFireEvents()
601
581
 
602
- sub:Destroy()
582
+ seenItems:Destroy()
603
583
 
604
584
  expect(#seenItems).toEqual(2)
605
- expect(seenItems[2]).toEqual(NIL_VALUE)
585
+ expect(seenItems[2]).toBeNil()
606
586
  maid:Destroy()
607
587
  end)
608
588
 
@@ -619,12 +599,9 @@ describe("ObservableSortedList", function()
619
599
  list:Add("c", sortValueC:Observe())
620
600
  list:_testForceFireEvents()
621
601
 
622
- local fireCount = 0
623
- local sub = list:Observe():Subscribe(function()
624
- fireCount += 1
625
- end)
602
+ local emissions = ObservableSpy.new(list:Observe())
626
603
 
627
- expect(fireCount).toEqual(1)
604
+ expect(#emissions).toEqual(1)
628
605
 
629
606
  sortValueA.Value = 30
630
607
  sortValueB.Value = 20
@@ -632,10 +609,10 @@ describe("ObservableSortedList", function()
632
609
 
633
610
  list:_testForceFireEvents()
634
611
 
635
- expect(fireCount).toEqual(2)
612
+ expect(#emissions).toEqual(2)
636
613
  expect(list:GetList()).toEqual({ "c", "b", "a" })
637
614
 
638
- sub:Destroy()
615
+ emissions:Destroy()
639
616
  maid:Destroy()
640
617
  end)
641
618
 
@@ -647,18 +624,15 @@ describe("ObservableSortedList", function()
647
624
  list:Add("b", 2)
648
625
  list:_testForceFireEvents()
649
626
 
650
- local completed = false
651
- local sub = list:ObserveIndex(1):Subscribe(function() end, function() end, function()
652
- completed = true
653
- end)
627
+ local indexes = ObservableSpy.new(list:ObserveIndex(1))
654
628
 
655
- expect(completed).toEqual(false)
629
+ expect(indexes:IsComplete()).toEqual(false)
656
630
 
657
631
  removeA()
658
632
  list:_testForceFireEvents()
659
633
 
660
- expect(completed).toEqual(true)
661
- sub:Destroy()
634
+ expect(indexes:IsComplete()).toEqual(true)
635
+ indexes:Destroy()
662
636
  maid:Destroy()
663
637
  end)
664
638
 
@@ -667,11 +641,11 @@ describe("ObservableSortedList", function()
667
641
  local list = maid:Add(ObservableSortedListTestUtils.fromList({ "a", "b" }))
668
642
  list:_testForceFireEvents()
669
643
 
670
- local seenBrios, sub = ObservableSortedListTestUtils.collectValues(list:ObserveItemsBrio())
644
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
671
645
 
672
646
  expect(#seenBrios).toEqual(2)
673
647
 
674
- sub:Destroy()
648
+ seenBrios:Destroy()
675
649
  maid:Destroy()
676
650
  end)
677
651
 
@@ -706,20 +680,17 @@ describe("ObservableSortedList", function()
706
680
  list:Add("c", 3)
707
681
  list:_testForceFireEvents()
708
682
 
709
- local fireCount = 0
710
- local sub = list:Observe():Subscribe(function()
711
- fireCount += 1
712
- end)
683
+ local emissions = ObservableSpy.new(list:Observe())
713
684
 
714
- expect(fireCount).toEqual(1)
685
+ expect(#emissions).toEqual(1)
715
686
 
716
687
  sortValue.Value = 2
717
688
  list:_testForceFireEvents()
718
689
 
719
- expect(fireCount).toEqual(1)
690
+ expect(#emissions).toEqual(1)
720
691
  expect(list:GetList()).toEqual({ "a", "b", "c" })
721
692
 
722
- sub:Destroy()
693
+ emissions:Destroy()
723
694
  maid:Destroy()
724
695
  end)
725
696
 
@@ -758,11 +729,8 @@ describe("ObservableSortedList", function()
758
729
  list:Add("c", 3)
759
730
  list:_testForceFireEvents()
760
731
 
761
- local fireCount = 0
762
- local sub = list:Observe():Subscribe(function()
763
- fireCount += 1
764
- end)
765
- expect(fireCount).toEqual(1)
732
+ local emissions = ObservableSpy.new(list:Observe())
733
+ expect(#emissions).toEqual(1)
766
734
 
767
735
  sortValue.Value = 10
768
736
  sortValue.Value = 1
@@ -772,7 +740,7 @@ describe("ObservableSortedList", function()
772
740
 
773
741
  expect(list:GetList()).toEqual({ "a", "b", "c" })
774
742
 
775
- sub:Destroy()
743
+ emissions:Destroy()
776
744
  maid:Destroy()
777
745
  end)
778
746
 
@@ -842,7 +810,7 @@ describe("ObservableSortedList", function()
842
810
  list:Add("c", 10)
843
811
  list:_testForceFireEvents()
844
812
 
845
- local seenIndices, sub = ObservableSortedListTestUtils.collectValues(list:ObserveIndex(2))
813
+ local seenIndices = ObservableSpy.new(list:ObserveIndex(2))
846
814
  expect(seenIndices[1]).toEqual(2)
847
815
 
848
816
  sortB.Value = 7
@@ -851,7 +819,7 @@ describe("ObservableSortedList", function()
851
819
  expect(#seenIndices).toEqual(1)
852
820
  expect(list:GetList()).toEqual({ "a", "b", "c" })
853
821
 
854
- sub:Destroy()
822
+ seenIndices:Destroy()
855
823
  maid:Destroy()
856
824
  end)
857
825
  end)
@@ -906,7 +874,7 @@ describe("ObservableSortedList", function()
906
874
  list:Add("b", sortValue:Observe())
907
875
  list:_testForceFireEvents()
908
876
 
909
- local seenBrios, sub = ObservableSortedListTestUtils.collectValues(list:ObserveItemsBrio())
877
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
910
878
  expect(#seenBrios).toEqual(2)
911
879
  expect(seenBrios[1]:IsDead()).toEqual(false)
912
880
  expect(seenBrios[2]:IsDead()).toEqual(false)
@@ -917,7 +885,7 @@ describe("ObservableSortedList", function()
917
885
  expect(seenBrios[2]:IsDead()).toEqual(true)
918
886
  expect(seenBrios[1]:IsDead()).toEqual(false)
919
887
 
920
- sub:Destroy()
888
+ seenBrios:Destroy()
921
889
  maid:Destroy()
922
890
  end)
923
891
 
@@ -993,22 +961,16 @@ describe("ObservableSortedList", function()
993
961
  list:Add("a", 1)
994
962
  list:_testForceFireEvents()
995
963
 
996
- local addCount = 0
997
- local removeCount = 0
998
- maid:Add(list.ItemAdded:Connect(function()
999
- addCount += 1
1000
- end))
1001
- maid:Add(list.ItemRemoved:Connect(function()
1002
- removeCount += 1
1003
- end))
964
+ local addCount = SignalTestUtils.countFires(maid, list.ItemAdded)
965
+ local removeCount = SignalTestUtils.countFires(maid, list.ItemRemoved)
1004
966
 
1005
967
  local remove = list:Add("b", 2)
1006
968
  remove()
1007
969
 
1008
970
  list:_testForceFireEvents()
1009
971
 
1010
- expect(addCount).toEqual(0)
1011
- expect(removeCount).toEqual(0)
972
+ expect(addCount()).toEqual(0)
973
+ expect(removeCount()).toEqual(0)
1012
974
  expect(list:GetList()).toEqual({ "a" })
1013
975
 
1014
976
  maid:Destroy()
@@ -1020,10 +982,7 @@ describe("ObservableSortedList", function()
1020
982
 
1021
983
  local remove = list:Add("a", 1)
1022
984
 
1023
- local brios: { any } = {}
1024
- maid:GiveTask(list:ObserveItemsBrio():Subscribe(function(brio)
1025
- table.insert(brios, brio)
1026
- end))
985
+ local brios = maid:Add(ObservableSpy.new(list:ObserveItemsBrio()))
1027
986
 
1028
987
  expect(#brios).toEqual(1)
1029
988
  expect(brios[1]:IsDead()).toEqual(false)
@@ -1047,10 +1006,7 @@ describe("ObservableSortedList", function()
1047
1006
  local remove = list:Add("a", 1)
1048
1007
  list:_testForceFireEvents()
1049
1008
 
1050
- local brios: { any } = {}
1051
- maid:GiveTask(list:ObserveItemsBrio():Subscribe(function(brio)
1052
- table.insert(brios, brio)
1053
- end))
1009
+ local brios = maid:Add(ObservableSpy.new(list:ObserveItemsBrio()))
1054
1010
 
1055
1011
  expect(#brios).toEqual(1)
1056
1012
 
@@ -1068,10 +1024,7 @@ describe("ObservableSortedList", function()
1068
1024
  local remove = list:Add("a", 1)
1069
1025
  remove()
1070
1026
 
1071
- local brios: { any } = {}
1072
- maid:GiveTask(list:ObserveItemsBrio():Subscribe(function(brio)
1073
- table.insert(brios, brio)
1074
- end))
1027
+ local brios = maid:Add(ObservableSpy.new(list:ObserveItemsBrio()))
1075
1028
 
1076
1029
  list:_testForceFireEvents()
1077
1030
 
@@ -1086,10 +1039,7 @@ describe("ObservableSortedList", function()
1086
1039
 
1087
1040
  list:Add("a", 1)
1088
1041
 
1089
- local brios: { any } = {}
1090
- maid:GiveTask(list:ObserveItemsBrio():Subscribe(function(brio)
1091
- table.insert(brios, brio)
1092
- end))
1042
+ local brios = maid:Add(ObservableSpy.new(list:ObserveItemsBrio()))
1093
1043
 
1094
1044
  expect(#brios).toEqual(1)
1095
1045
 
@@ -1105,10 +1055,7 @@ describe("ObservableSortedList", function()
1105
1055
  local maid = Maid.new()
1106
1056
  local list = maid:Add(ObservableSortedList.new())
1107
1057
 
1108
- local brios: { any } = {}
1109
- maid:GiveTask(list:ObserveItemsBrio():Subscribe(function(brio)
1110
- table.insert(brios, brio)
1111
- end))
1058
+ local brios = maid:Add(ObservableSpy.new(list:ObserveItemsBrio()))
1112
1059
 
1113
1060
  list:Add("a", 1)
1114
1061
  list:_testForceFireEvents()
@@ -1144,7 +1091,7 @@ describe("ObservableSortedList", function()
1144
1091
  local maid = Maid.new()
1145
1092
  local list = maid:Add(ObservableSortedList.new())
1146
1093
 
1147
- local counts, countSub = ObservableSortedListTestUtils.collectValues(list:ObserveCount())
1094
+ local counts = ObservableSpy.new(list:ObserveCount())
1148
1095
 
1149
1096
  list:Add("a", 1)
1150
1097
  list:Add("b", 2)
@@ -1156,7 +1103,7 @@ describe("ObservableSortedList", function()
1156
1103
  expect(counts[2]).toEqual(3)
1157
1104
  expect(#counts).toEqual(2)
1158
1105
 
1159
- countSub:Destroy()
1106
+ counts:Destroy()
1160
1107
  maid:Destroy()
1161
1108
  end)
1162
1109
 
@@ -1165,7 +1112,7 @@ describe("ObservableSortedList", function()
1165
1112
  local list = maid:Add(ObservableSortedList.new())
1166
1113
  list:_testForceFireEvents()
1167
1114
 
1168
- local counts, countSub = ObservableSortedListTestUtils.collectValues(list:ObserveCount())
1115
+ local counts = ObservableSpy.new(list:ObserveCount())
1169
1116
  expect(counts[1]).toEqual(0)
1170
1117
 
1171
1118
  local removeA = list:Add("a", 1)
@@ -1179,7 +1126,7 @@ describe("ObservableSortedList", function()
1179
1126
  expect(list:GetList()).toEqual({ "b", "c", "d" })
1180
1127
  expect(counts[2]).toEqual(3)
1181
1128
 
1182
- countSub:Destroy()
1129
+ counts:Destroy()
1183
1130
  maid:Destroy()
1184
1131
  end)
1185
1132
 
@@ -1237,10 +1184,7 @@ describe("ObservableSortedList", function()
1237
1184
  local list = maid:Add(ObservableSortedList.new())
1238
1185
  list:_testForceFireEvents()
1239
1186
 
1240
- local addedItems: { string } = {}
1241
- maid:Add(list.ItemAdded:Connect(function(data)
1242
- table.insert(addedItems, data)
1243
- end))
1187
+ local addedItems = SignalTestUtils.collectFireList(maid, list.ItemAdded)
1244
1188
 
1245
1189
  list:Add("c", 3)
1246
1190
  list:Add("a", 1)
@@ -1261,7 +1205,7 @@ describe("ObservableSortedList", function()
1261
1205
  list:Add("c", 10)
1262
1206
  list:_testForceFireEvents()
1263
1207
 
1264
- local indexChanges, sub = ObservableSortedListTestUtils.collectValues(list:ObserveIndex(2))
1208
+ local indexChanges = ObservableSpy.new(list:ObserveIndex(2))
1265
1209
  expect(#indexChanges).toEqual(1)
1266
1210
 
1267
1211
  sortB.Value = 8
@@ -1270,7 +1214,7 @@ describe("ObservableSortedList", function()
1270
1214
  expect(#indexChanges).toEqual(1)
1271
1215
  expect(list:Get(2)).toEqual("b")
1272
1216
 
1273
- sub:Destroy()
1217
+ indexChanges:Destroy()
1274
1218
  maid:Destroy()
1275
1219
  end)
1276
1220
 
@@ -1284,7 +1228,7 @@ describe("ObservableSortedList", function()
1284
1228
  list:Add("c", 3)
1285
1229
  list:_testForceFireEvents()
1286
1230
 
1287
- local seenAtIndex1, sub = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1231
+ local seenAtIndex1 = ObservableSpy.new(list:ObserveAtIndex(1))
1288
1232
  expect(seenAtIndex1[1]).toEqual("a")
1289
1233
 
1290
1234
  sortA.Value = 10
@@ -1292,7 +1236,7 @@ describe("ObservableSortedList", function()
1292
1236
 
1293
1237
  expect(seenAtIndex1[2]).toEqual("b")
1294
1238
 
1295
- sub:Destroy()
1239
+ seenAtIndex1:Destroy()
1296
1240
  maid:Destroy()
1297
1241
  end)
1298
1242
 
@@ -1305,10 +1249,7 @@ describe("ObservableSortedList", function()
1305
1249
  list:Add("b", sortValue:Observe())
1306
1250
  list:_testForceFireEvents()
1307
1251
 
1308
- local seenBrios: { Brio.Brio<string, any> } = {}
1309
- local sub = list:ObserveItemsBrio():Subscribe(function(brio)
1310
- table.insert(seenBrios, brio)
1311
- end)
1252
+ local seenBrios = ObservableSpy.new(list:ObserveItemsBrio())
1312
1253
 
1313
1254
  expect(#seenBrios).toEqual(2)
1314
1255
 
@@ -1323,7 +1264,7 @@ describe("ObservableSortedList", function()
1323
1264
  expect(#seenBrios).toEqual(3)
1324
1265
  expect(seenBrios[3]:IsDead()).toEqual(false)
1325
1266
 
1326
- sub:Destroy()
1267
+ seenBrios:Destroy()
1327
1268
  maid:Destroy()
1328
1269
  end)
1329
1270
 
@@ -1441,8 +1382,8 @@ describe("ObservableSortedList", function()
1441
1382
  list:Add("e", 5)
1442
1383
  list:_testForceFireEvents()
1443
1384
 
1444
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1445
- local fires5, sub5 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(5))
1385
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1386
+ local fires5 = ObservableSpy.new(list:ObserveAtIndex(5))
1446
1387
 
1447
1388
  expect(#fires1).toEqual(1)
1448
1389
  expect(#fires5).toEqual(1)
@@ -1454,8 +1395,8 @@ describe("ObservableSortedList", function()
1454
1395
  expect(#fires1).toEqual(1)
1455
1396
  expect(#fires5).toEqual(1)
1456
1397
 
1457
- sub1:Destroy()
1458
- sub5:Destroy()
1398
+ fires1:Destroy()
1399
+ fires5:Destroy()
1459
1400
  maid:Destroy()
1460
1401
  end)
1461
1402
 
@@ -1475,8 +1416,8 @@ describe("ObservableSortedList", function()
1475
1416
  local nodeE = list:FindFirstKey("e")
1476
1417
  assert(nodeA and nodeE, "Expected nodes")
1477
1418
 
1478
- local firesA, subA = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeA))
1479
- local firesE, subE = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeE))
1419
+ local firesA = ObservableSpy.new(list:ObserveIndexByKey(nodeA))
1420
+ local firesE = ObservableSpy.new(list:ObserveIndexByKey(nodeE))
1480
1421
 
1481
1422
  expect(#firesA).toEqual(1)
1482
1423
  expect(#firesE).toEqual(1)
@@ -1487,8 +1428,8 @@ describe("ObservableSortedList", function()
1487
1428
  expect(#firesA).toEqual(1)
1488
1429
  expect(#firesE).toEqual(1)
1489
1430
 
1490
- subA:Destroy()
1491
- subE:Destroy()
1431
+ firesA:Destroy()
1432
+ firesE:Destroy()
1492
1433
  maid:Destroy()
1493
1434
  end)
1494
1435
 
@@ -1503,10 +1444,10 @@ describe("ObservableSortedList", function()
1503
1444
  local removeE = list:Add("e", 5)
1504
1445
  list:_testForceFireEvents()
1505
1446
 
1506
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1507
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1508
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1509
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
1447
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1448
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1449
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1450
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
1510
1451
 
1511
1452
  expect(#fires1).toEqual(1)
1512
1453
  expect(#fires2).toEqual(1)
@@ -1522,10 +1463,10 @@ describe("ObservableSortedList", function()
1522
1463
  expect(#fires3).toEqual(1)
1523
1464
  expect(#fires4).toEqual(1)
1524
1465
 
1525
- sub1:Destroy()
1526
- sub2:Destroy()
1527
- sub3:Destroy()
1528
- sub4:Destroy()
1466
+ fires1:Destroy()
1467
+ fires2:Destroy()
1468
+ fires3:Destroy()
1469
+ fires4:Destroy()
1529
1470
  maid:Destroy()
1530
1471
  end)
1531
1472
 
@@ -1538,9 +1479,9 @@ describe("ObservableSortedList", function()
1538
1479
  list:Add("c", 3)
1539
1480
  list:_testForceFireEvents()
1540
1481
 
1541
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1542
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1543
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1482
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1483
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1484
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1544
1485
 
1545
1486
  expect(#fires1).toEqual(1)
1546
1487
  expect(#fires2).toEqual(1)
@@ -1554,9 +1495,9 @@ describe("ObservableSortedList", function()
1554
1495
  expect(#fires2).toEqual(1)
1555
1496
  expect(#fires3).toEqual(1)
1556
1497
 
1557
- sub1:Destroy()
1558
- sub2:Destroy()
1559
- sub3:Destroy()
1498
+ fires1:Destroy()
1499
+ fires2:Destroy()
1500
+ fires3:Destroy()
1560
1501
  maid:Destroy()
1561
1502
  end)
1562
1503
 
@@ -1571,8 +1512,8 @@ describe("ObservableSortedList", function()
1571
1512
  list:Add("e", 5)
1572
1513
  list:_testForceFireEvents()
1573
1514
 
1574
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1575
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1515
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1516
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1576
1517
 
1577
1518
  expect(#fires1).toEqual(1)
1578
1519
  expect(#fires2).toEqual(1)
@@ -1584,8 +1525,8 @@ describe("ObservableSortedList", function()
1584
1525
  expect(#fires1).toEqual(1)
1585
1526
  expect(#fires2).toEqual(1)
1586
1527
 
1587
- sub1:Destroy()
1588
- sub2:Destroy()
1528
+ fires1:Destroy()
1529
+ fires2:Destroy()
1589
1530
  maid:Destroy()
1590
1531
  end)
1591
1532
 
@@ -1600,7 +1541,7 @@ describe("ObservableSortedList", function()
1600
1541
  list:Add("e", 5)
1601
1542
  list:_testForceFireEvents()
1602
1543
 
1603
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
1544
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
1604
1545
  expect(#fires4).toEqual(1)
1605
1546
  expect(fires4[1]).toEqual("d")
1606
1547
 
@@ -1611,7 +1552,7 @@ describe("ObservableSortedList", function()
1611
1552
  expect(#fires4).toEqual(2)
1612
1553
  expect(fires4[2]).toEqual("e")
1613
1554
 
1614
- sub4:Destroy()
1555
+ fires4:Destroy()
1615
1556
  maid:Destroy()
1616
1557
  end)
1617
1558
 
@@ -1630,8 +1571,8 @@ describe("ObservableSortedList", function()
1630
1571
  local nodeE = list:FindFirstKey("e")
1631
1572
  assert(nodeD and nodeE, "Expected nodes")
1632
1573
 
1633
- local firesD, subD = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeD))
1634
- local firesE, subE = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeE))
1574
+ local firesD = ObservableSpy.new(list:ObserveIndexByKey(nodeD))
1575
+ local firesE = ObservableSpy.new(list:ObserveIndexByKey(nodeE))
1635
1576
 
1636
1577
  expect(firesD[1]).toEqual(4)
1637
1578
  expect(firesE[1]).toEqual(5)
@@ -1644,8 +1585,8 @@ describe("ObservableSortedList", function()
1644
1585
  expect(#firesE).toEqual(2)
1645
1586
  expect(firesE[2]).toEqual(4)
1646
1587
 
1647
- subD:Destroy()
1648
- subE:Destroy()
1588
+ firesD:Destroy()
1589
+ firesE:Destroy()
1649
1590
  maid:Destroy()
1650
1591
  end)
1651
1592
 
@@ -1660,9 +1601,9 @@ describe("ObservableSortedList", function()
1660
1601
  list:Add("e", 5)
1661
1602
  list:_testForceFireEvents()
1662
1603
 
1663
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1664
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
1665
- local fires5, sub5 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(5))
1604
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1605
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
1606
+ local fires5 = ObservableSpy.new(list:ObserveAtIndex(5))
1666
1607
 
1667
1608
  expect(#fires3).toEqual(1)
1668
1609
  expect(#fires4).toEqual(1)
@@ -1678,9 +1619,9 @@ describe("ObservableSortedList", function()
1678
1619
  expect(#fires4).toEqual(1)
1679
1620
  expect(#fires5).toEqual(1)
1680
1621
 
1681
- sub3:Destroy()
1682
- sub4:Destroy()
1683
- sub5:Destroy()
1622
+ fires3:Destroy()
1623
+ fires4:Destroy()
1624
+ fires5:Destroy()
1684
1625
  maid:Destroy()
1685
1626
  end)
1686
1627
 
@@ -1700,9 +1641,9 @@ describe("ObservableSortedList", function()
1700
1641
  local nodeE = list:FindFirstKey("e")
1701
1642
  assert(nodeC and nodeD and nodeE, "Expected nodes")
1702
1643
 
1703
- local firesC, subC = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeC))
1704
- local firesD, subD = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeD))
1705
- local firesE, subE = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeE))
1644
+ local firesC = ObservableSpy.new(list:ObserveIndexByKey(nodeC))
1645
+ local firesD = ObservableSpy.new(list:ObserveIndexByKey(nodeD))
1646
+ local firesE = ObservableSpy.new(list:ObserveIndexByKey(nodeE))
1706
1647
 
1707
1648
  expect(#firesC).toEqual(1)
1708
1649
  expect(#firesD).toEqual(1)
@@ -1717,9 +1658,9 @@ describe("ObservableSortedList", function()
1717
1658
  expect(#firesD).toEqual(1)
1718
1659
  expect(#firesE).toEqual(1)
1719
1660
 
1720
- subC:Destroy()
1721
- subD:Destroy()
1722
- subE:Destroy()
1661
+ firesC:Destroy()
1662
+ firesD:Destroy()
1663
+ firesE:Destroy()
1723
1664
  maid:Destroy()
1724
1665
  end)
1725
1666
 
@@ -1734,7 +1675,7 @@ describe("ObservableSortedList", function()
1734
1675
  list:Add("e", 5)
1735
1676
  list:_testForceFireEvents()
1736
1677
 
1737
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1678
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1738
1679
  expect(#fires3).toEqual(1)
1739
1680
  expect(fires3[1]).toEqual("c")
1740
1681
 
@@ -1747,7 +1688,7 @@ describe("ObservableSortedList", function()
1747
1688
  expect(#fires3).toEqual(2)
1748
1689
  expect(fires3[2]).toEqual("d")
1749
1690
 
1750
- sub3:Destroy()
1691
+ fires3:Destroy()
1751
1692
  maid:Destroy()
1752
1693
  end)
1753
1694
 
@@ -1766,8 +1707,8 @@ describe("ObservableSortedList", function()
1766
1707
  local nodeD = list:FindFirstKey("d")
1767
1708
  assert(nodeC and nodeD, "Expected nodes")
1768
1709
 
1769
- local firesC, subC = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeC))
1770
- local firesD, subD = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeD))
1710
+ local firesC = ObservableSpy.new(list:ObserveIndexByKey(nodeC))
1711
+ local firesD = ObservableSpy.new(list:ObserveIndexByKey(nodeD))
1771
1712
 
1772
1713
  expect(firesC[1]).toEqual(3)
1773
1714
  expect(firesD[1]).toEqual(4)
@@ -1783,8 +1724,8 @@ describe("ObservableSortedList", function()
1783
1724
  expect(#firesD).toEqual(2)
1784
1725
  expect(firesD[2]).toEqual(3)
1785
1726
 
1786
- subC:Destroy()
1787
- subD:Destroy()
1727
+ firesC:Destroy()
1728
+ firesD:Destroy()
1788
1729
  maid:Destroy()
1789
1730
  end)
1790
1731
 
@@ -1799,7 +1740,7 @@ describe("ObservableSortedList", function()
1799
1740
  list:Add("e", 5)
1800
1741
  list:_testForceFireEvents()
1801
1742
 
1802
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1743
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1803
1744
  expect(fires3[1]).toEqual("c")
1804
1745
 
1805
1746
  removeB()
@@ -1812,7 +1753,7 @@ describe("ObservableSortedList", function()
1812
1753
 
1813
1754
  expect(#fires3).toEqual(1)
1814
1755
 
1815
- sub3:Destroy()
1756
+ fires3:Destroy()
1816
1757
  maid:Destroy()
1817
1758
  end)
1818
1759
 
@@ -1826,9 +1767,9 @@ describe("ObservableSortedList", function()
1826
1767
  list:Add("d", 4)
1827
1768
  list:_testForceFireEvents()
1828
1769
 
1829
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1830
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1831
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1770
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1771
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1772
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1832
1773
 
1833
1774
  expect(fires1[1]).toEqual("a")
1834
1775
  expect(fires2[1]).toEqual("b")
@@ -1845,9 +1786,9 @@ describe("ObservableSortedList", function()
1845
1786
  expect(#fires3).toEqual(2)
1846
1787
  expect(fires3[2]).toEqual("d")
1847
1788
 
1848
- sub1:Destroy()
1849
- sub2:Destroy()
1850
- sub3:Destroy()
1789
+ fires1:Destroy()
1790
+ fires2:Destroy()
1791
+ fires3:Destroy()
1851
1792
  maid:Destroy()
1852
1793
  end)
1853
1794
 
@@ -1862,9 +1803,9 @@ describe("ObservableSortedList", function()
1862
1803
  list:Add("e", 5)
1863
1804
  list:_testForceFireEvents()
1864
1805
 
1865
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1866
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1867
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
1806
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1807
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1808
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
1868
1809
 
1869
1810
  expect(fires2[1]).toEqual("b")
1870
1811
  expect(fires3[1]).toEqual("c")
@@ -1880,11 +1821,11 @@ describe("ObservableSortedList", function()
1880
1821
  expect(#fires3).toEqual(2)
1881
1822
  expect(fires3[2]).toEqual("e")
1882
1823
  expect(#fires4).toEqual(2)
1883
- expect(fires4[2]).toEqual(NIL_VALUE)
1824
+ expect(fires4[2]).toBeNil()
1884
1825
 
1885
- sub2:Destroy()
1886
- sub3:Destroy()
1887
- sub4:Destroy()
1826
+ fires2:Destroy()
1827
+ fires3:Destroy()
1828
+ fires4:Destroy()
1888
1829
  maid:Destroy()
1889
1830
  end)
1890
1831
 
@@ -1897,9 +1838,9 @@ describe("ObservableSortedList", function()
1897
1838
  list:Add("d", 4)
1898
1839
  list:_testForceFireEvents()
1899
1840
 
1900
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1901
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
1902
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1841
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1842
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1843
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1903
1844
 
1904
1845
  expect(fires1[1]).toEqual("b")
1905
1846
  expect(fires2[1]).toEqual("c")
@@ -1916,9 +1857,9 @@ describe("ObservableSortedList", function()
1916
1857
  expect(#fires3).toEqual(2)
1917
1858
  expect(fires3[2]).toEqual("c")
1918
1859
 
1919
- sub1:Destroy()
1920
- sub2:Destroy()
1921
- sub3:Destroy()
1860
+ fires1:Destroy()
1861
+ fires2:Destroy()
1862
+ fires3:Destroy()
1922
1863
  maid:Destroy()
1923
1864
  end)
1924
1865
 
@@ -1938,9 +1879,9 @@ describe("ObservableSortedList", function()
1938
1879
  local nodeD = list:FindFirstKey("d")
1939
1880
  assert(nodeB and nodeC and nodeD, "Expected nodes")
1940
1881
 
1941
- local firesB, subB = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeB))
1942
- local firesC, subC = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeC))
1943
- local firesD, subD = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeD))
1882
+ local firesB = ObservableSpy.new(list:ObserveIndexByKey(nodeB))
1883
+ local firesC = ObservableSpy.new(list:ObserveIndexByKey(nodeC))
1884
+ local firesD = ObservableSpy.new(list:ObserveIndexByKey(nodeD))
1944
1885
 
1945
1886
  expect(firesB[1]).toEqual(2)
1946
1887
  expect(firesC[1]).toEqual(3)
@@ -1957,9 +1898,9 @@ describe("ObservableSortedList", function()
1957
1898
  expect(#firesD).toEqual(2)
1958
1899
  expect(firesD[2]).toEqual(3)
1959
1900
 
1960
- subB:Destroy()
1961
- subC:Destroy()
1962
- subD:Destroy()
1901
+ firesB:Destroy()
1902
+ firesC:Destroy()
1903
+ firesD:Destroy()
1963
1904
  maid:Destroy()
1964
1905
  end)
1965
1906
 
@@ -1973,9 +1914,9 @@ describe("ObservableSortedList", function()
1973
1914
  list:Add("d", 4)
1974
1915
  list:_testForceFireEvents()
1975
1916
 
1976
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
1977
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1978
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
1917
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1918
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
1919
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
1979
1920
 
1980
1921
  expect(fires1[1]).toEqual("a")
1981
1922
  expect(fires3[1]).toEqual("c")
@@ -1990,9 +1931,9 @@ describe("ObservableSortedList", function()
1990
1931
  expect(#fires3).toEqual(1)
1991
1932
  expect(#fires4).toEqual(1)
1992
1933
 
1993
- sub1:Destroy()
1994
- sub3:Destroy()
1995
- sub4:Destroy()
1934
+ fires1:Destroy()
1935
+ fires3:Destroy()
1936
+ fires4:Destroy()
1996
1937
  maid:Destroy()
1997
1938
  end)
1998
1939
 
@@ -2008,9 +1949,9 @@ describe("ObservableSortedList", function()
2008
1949
  list:Add("e", 5)
2009
1950
  list:_testForceFireEvents()
2010
1951
 
2011
- local fires1, sub1 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(1))
2012
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
2013
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
1952
+ local fires1 = ObservableSpy.new(list:ObserveAtIndex(1))
1953
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
1954
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
2014
1955
 
2015
1956
  expect(fires1[1]).toEqual("a")
2016
1957
  expect(fires2[1]).toEqual("b")
@@ -2024,9 +1965,9 @@ describe("ObservableSortedList", function()
2024
1965
  expect(#fires2).toEqual(1)
2025
1966
  expect(#fires3).toEqual(1)
2026
1967
 
2027
- sub1:Destroy()
2028
- sub2:Destroy()
2029
- sub3:Destroy()
1968
+ fires1:Destroy()
1969
+ fires2:Destroy()
1970
+ fires3:Destroy()
2030
1971
  maid:Destroy()
2031
1972
  end)
2032
1973
 
@@ -2047,8 +1988,8 @@ describe("ObservableSortedList", function()
2047
1988
  local nodeE = list:FindFirstKey("e")
2048
1989
  assert(nodeA and nodeE, "Expected nodes")
2049
1990
 
2050
- local firesA, subA = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeA))
2051
- local firesE, subE = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeE))
1991
+ local firesA = ObservableSpy.new(list:ObserveIndexByKey(nodeA))
1992
+ local firesE = ObservableSpy.new(list:ObserveIndexByKey(nodeE))
2052
1993
 
2053
1994
  expect(firesA[1]).toEqual(1)
2054
1995
  expect(firesE[1]).toEqual(5)
@@ -2063,8 +2004,8 @@ describe("ObservableSortedList", function()
2063
2004
  expect(#firesA).toEqual(1)
2064
2005
  expect(#firesE).toEqual(1)
2065
2006
 
2066
- subA:Destroy()
2067
- subE:Destroy()
2007
+ firesA:Destroy()
2008
+ firesE:Destroy()
2068
2009
  maid:Destroy()
2069
2010
  end
2070
2011
  )
@@ -2082,9 +2023,9 @@ describe("ObservableSortedList", function()
2082
2023
  local removeE = list:Add("e", 5)
2083
2024
  list:_testForceFireEvents()
2084
2025
 
2085
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
2086
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
2087
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
2026
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
2027
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
2028
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
2088
2029
 
2089
2030
  expect(fires2[1]).toEqual("b")
2090
2031
  expect(fires3[1]).toEqual("c")
@@ -2101,9 +2042,9 @@ describe("ObservableSortedList", function()
2101
2042
  expect(#fires3).toEqual(1)
2102
2043
  expect(#fires4).toEqual(1)
2103
2044
 
2104
- sub2:Destroy()
2105
- sub3:Destroy()
2106
- sub4:Destroy()
2045
+ fires2:Destroy()
2046
+ fires3:Destroy()
2047
+ fires4:Destroy()
2107
2048
  maid:Destroy()
2108
2049
  end
2109
2050
  )
@@ -2121,9 +2062,9 @@ describe("ObservableSortedList", function()
2121
2062
  list:Add("e", sortE:Observe())
2122
2063
  list:_testForceFireEvents()
2123
2064
 
2124
- local fires2, sub2 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(2))
2125
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
2126
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
2065
+ local fires2 = ObservableSpy.new(list:ObserveAtIndex(2))
2066
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
2067
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
2127
2068
 
2128
2069
  expect(fires2[1]).toEqual("b")
2129
2070
  expect(fires3[1]).toEqual("c")
@@ -2136,9 +2077,9 @@ describe("ObservableSortedList", function()
2136
2077
  expect(list:GetList()).toEqual({ "b", "a", "c", "e", "d" })
2137
2078
  expect(#fires3).toEqual(1)
2138
2079
 
2139
- sub2:Destroy()
2140
- sub3:Destroy()
2141
- sub4:Destroy()
2080
+ fires2:Destroy()
2081
+ fires3:Destroy()
2082
+ fires4:Destroy()
2142
2083
  maid:Destroy()
2143
2084
  end)
2144
2085
 
@@ -2158,7 +2099,7 @@ describe("ObservableSortedList", function()
2158
2099
  local nodeC = list:FindFirstKey("c")
2159
2100
  assert(nodeC, "Expected node for c")
2160
2101
 
2161
- local firesC, subC = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeC))
2102
+ local firesC = ObservableSpy.new(list:ObserveIndexByKey(nodeC))
2162
2103
  expect(firesC[1]).toEqual(3)
2163
2104
 
2164
2105
  removeA()
@@ -2170,7 +2111,7 @@ describe("ObservableSortedList", function()
2170
2111
  expect(list:GetList()).toEqual({ "f", "b", "c", "d", "g" })
2171
2112
  expect(#firesC).toEqual(1)
2172
2113
 
2173
- subC:Destroy()
2114
+ firesC:Destroy()
2174
2115
  maid:Destroy()
2175
2116
  end
2176
2117
  )
@@ -2188,7 +2129,7 @@ describe("ObservableSortedList", function()
2188
2129
  local removeE = list:Add("e", 5)
2189
2130
  list:_testForceFireEvents()
2190
2131
 
2191
- local fires5, sub5 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(5))
2132
+ local fires5 = ObservableSpy.new(list:ObserveAtIndex(5))
2192
2133
  expect(fires5[1]).toEqual("e")
2193
2134
 
2194
2135
  removeD()
@@ -2202,7 +2143,7 @@ describe("ObservableSortedList", function()
2202
2143
  expect(#fires5).toEqual(2)
2203
2144
  expect(fires5[2]).toEqual("c")
2204
2145
 
2205
- sub5:Destroy()
2146
+ fires5:Destroy()
2206
2147
  maid:Destroy()
2207
2148
  end)
2208
2149
 
@@ -2221,7 +2162,7 @@ describe("ObservableSortedList", function()
2221
2162
  local nodeF = list:FindFirstKey("f")
2222
2163
  assert(nodeF, "Expected node for f")
2223
2164
 
2224
- local firesF, subF = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeF))
2165
+ local firesF = ObservableSpy.new(list:ObserveIndexByKey(nodeF))
2225
2166
  expect(firesF[1]).toEqual(6)
2226
2167
 
2227
2168
  removeD()
@@ -2233,7 +2174,7 @@ describe("ObservableSortedList", function()
2233
2174
  expect(#firesF).toEqual(2)
2234
2175
  expect(firesF[2]).toEqual(4)
2235
2176
 
2236
- subF:Destroy()
2177
+ firesF:Destroy()
2237
2178
  maid:Destroy()
2238
2179
  end)
2239
2180
 
@@ -2250,8 +2191,8 @@ describe("ObservableSortedList", function()
2250
2191
  list:Add("g", 7)
2251
2192
  list:_testForceFireEvents()
2252
2193
 
2253
- local fires4, sub4 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(4))
2254
- local fires5, sub5 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(5))
2194
+ local fires4 = ObservableSpy.new(list:ObserveAtIndex(4))
2195
+ local fires5 = ObservableSpy.new(list:ObserveAtIndex(5))
2255
2196
 
2256
2197
  expect(fires4[1]).toEqual("d")
2257
2198
  expect(fires5[1]).toEqual("e")
@@ -2267,10 +2208,10 @@ describe("ObservableSortedList", function()
2267
2208
  expect(fires4[2]).toEqual("g")
2268
2209
 
2269
2210
  expect(#fires5).toEqual(2)
2270
- expect(fires5[2]).toEqual(NIL_VALUE)
2211
+ expect(fires5[2]).toBeNil()
2271
2212
 
2272
- sub4:Destroy()
2273
- sub5:Destroy()
2213
+ fires4:Destroy()
2214
+ fires5:Destroy()
2274
2215
  maid:Destroy()
2275
2216
  end)
2276
2217
 
@@ -2283,7 +2224,7 @@ describe("ObservableSortedList", function()
2283
2224
  list:Add("c", 3)
2284
2225
  list:_testForceFireEvents()
2285
2226
 
2286
- local fires3, sub3 = ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(3))
2227
+ local fires3 = ObservableSpy.new(list:ObserveAtIndex(3))
2287
2228
  expect(fires3[1]).toEqual("c")
2288
2229
 
2289
2230
  list:Add("x", 0.1)
@@ -2296,7 +2237,7 @@ describe("ObservableSortedList", function()
2296
2237
  expect(#fires3).toEqual(2)
2297
2238
  expect(fires3[2]).toEqual("z")
2298
2239
 
2299
- sub3:Destroy()
2240
+ fires3:Destroy()
2300
2241
  maid:Destroy()
2301
2242
  end)
2302
2243
 
@@ -2314,7 +2255,7 @@ describe("ObservableSortedList", function()
2314
2255
  local nodeE = list:FindFirstKey("e")
2315
2256
  assert(nodeE, "Expected node for e")
2316
2257
 
2317
- local firesE, subE = ObservableSortedListTestUtils.collectValues(list:ObserveIndexByKey(nodeE))
2258
+ local firesE = ObservableSpy.new(list:ObserveIndexByKey(nodeE))
2318
2259
  expect(firesE[1]).toEqual(5)
2319
2260
 
2320
2261
  removeA()
@@ -2327,16 +2268,12 @@ describe("ObservableSortedList", function()
2327
2268
  expect(#firesE).toEqual(2)
2328
2269
  expect(firesE[2]).toEqual(2)
2329
2270
 
2330
- subE:Destroy()
2271
+ firesE:Destroy()
2331
2272
  maid:Destroy()
2332
2273
  end)
2333
2274
  end)
2334
2275
  end)
2335
2276
 
2336
- local function observe(list, index: number)
2337
- return ObservableSortedListTestUtils.collectValues(list:ObserveAtIndex(index))
2338
- end
2339
-
2340
2277
  describe("ObservableSortedList negative index observation (mirrors ObservableList)", function()
2341
2278
  it("moves the last item back when a later item is added", function()
2342
2279
  local maid = Maid.new()
@@ -2344,17 +2281,20 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2344
2281
  list:Add("a", 1)
2345
2282
  list:_testForceFireEvents()
2346
2283
 
2347
- local seenLast, subLast = observe(list, -1)
2348
- local seenSecondLast, subSecondLast = observe(list, -2)
2284
+ local seenLast = ObservableSpy.new(list:ObserveAtIndex(-1))
2285
+ local seenSecondLast = ObservableSpy.new(list:ObserveAtIndex(-2))
2349
2286
 
2350
2287
  list:Add("b", 2)
2351
2288
  list:_testForceFireEvents()
2352
2289
 
2353
- expect(seenLast).toEqual({ "a", "b" })
2354
- expect(seenSecondLast).toEqual({ NIL_VALUE, "a" })
2290
+ expect(#seenLast).toEqual(2)
2291
+ expect(seenLast.Values).toEqual({ "a", "b" })
2292
+ expect(#seenSecondLast).toEqual(2)
2293
+ expect(seenSecondLast[1]).toBeNil()
2294
+ expect(seenSecondLast[2]).toEqual("a")
2355
2295
 
2356
- subLast:Destroy()
2357
- subSecondLast:Destroy()
2296
+ seenLast:Destroy()
2297
+ seenSecondLast:Destroy()
2358
2298
  maid:Destroy()
2359
2299
  end)
2360
2300
 
@@ -2365,14 +2305,15 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2365
2305
  local removeB = list:Add("b", 2)
2366
2306
  list:_testForceFireEvents()
2367
2307
 
2368
- local seen, sub = observe(list, -1)
2308
+ local seen = ObservableSpy.new(list:ObserveAtIndex(-1))
2369
2309
 
2370
2310
  removeB()
2371
2311
  list:_testForceFireEvents()
2372
2312
 
2373
- expect(seen).toEqual({ "b", "a" })
2313
+ expect(#seen).toEqual(2)
2314
+ expect(seen.Values).toEqual({ "b", "a" })
2374
2315
 
2375
- sub:Destroy()
2316
+ seen:Destroy()
2376
2317
  maid:Destroy()
2377
2318
  end)
2378
2319
 
@@ -2383,14 +2324,16 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2383
2324
  list:Add("b", 2)
2384
2325
  list:_testForceFireEvents()
2385
2326
 
2386
- local seen, sub = observe(list, -2)
2327
+ local seen = ObservableSpy.new(list:ObserveAtIndex(-2))
2387
2328
 
2388
2329
  removeA()
2389
2330
  list:_testForceFireEvents()
2390
2331
 
2391
- expect(seen).toEqual({ "a", NIL_VALUE })
2332
+ expect(#seen).toEqual(2)
2333
+ expect(seen[1]).toEqual("a")
2334
+ expect(seen[2]).toBeNil()
2392
2335
 
2393
- sub:Destroy()
2336
+ seen:Destroy()
2394
2337
  maid:Destroy()
2395
2338
  end)
2396
2339
 
@@ -2401,14 +2344,15 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2401
2344
  list:Add("b", 2)
2402
2345
  list:_testForceFireEvents()
2403
2346
 
2404
- local seen, sub = observe(list, -1)
2347
+ local seen = ObservableSpy.new(list:ObserveAtIndex(-1))
2405
2348
 
2406
2349
  removeA()
2407
2350
  list:_testForceFireEvents()
2408
2351
 
2409
- expect(seen).toEqual({ "b" })
2352
+ expect(#seen).toEqual(1)
2353
+ expect(seen.Values).toEqual({ "b" })
2410
2354
 
2411
- sub:Destroy()
2355
+ seen:Destroy()
2412
2356
  maid:Destroy()
2413
2357
  end)
2414
2358
 
@@ -2419,17 +2363,20 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2419
2363
  local removeB = list:Add("b", 2)
2420
2364
  list:_testForceFireEvents()
2421
2365
 
2422
- local seenFirst, subFirst = observe(list, 1)
2423
- local seenSecond, subSecond = observe(list, 2)
2366
+ local seenFirst = ObservableSpy.new(list:ObserveAtIndex(1))
2367
+ local seenSecond = ObservableSpy.new(list:ObserveAtIndex(2))
2424
2368
 
2425
2369
  removeB()
2426
2370
  list:_testForceFireEvents()
2427
2371
 
2428
- expect(seenFirst).toEqual({ "a" })
2429
- expect(seenSecond).toEqual({ "b", NIL_VALUE })
2372
+ expect(#seenFirst).toEqual(1)
2373
+ expect(seenFirst.Values).toEqual({ "a" })
2374
+ expect(#seenSecond).toEqual(2)
2375
+ expect(seenSecond[1]).toEqual("b")
2376
+ expect(seenSecond[2]).toBeNil()
2430
2377
 
2431
- subFirst:Destroy()
2432
- subSecond:Destroy()
2378
+ seenFirst:Destroy()
2379
+ seenSecond:Destroy()
2433
2380
  maid:Destroy()
2434
2381
  end)
2435
2382
 
@@ -2441,24 +2388,29 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2441
2388
  list:Add("c", 3)
2442
2389
  list:_testForceFireEvents()
2443
2390
 
2444
- local seen4, sub4 = observe(list, -4)
2445
- local seen3, sub3 = observe(list, -3)
2446
- local seen2, sub2 = observe(list, -2)
2447
- local seen1, sub1 = observe(list, -1)
2391
+ local seen4 = ObservableSpy.new(list:ObserveAtIndex(-4))
2392
+ local seen3 = ObservableSpy.new(list:ObserveAtIndex(-3))
2393
+ local seen2 = ObservableSpy.new(list:ObserveAtIndex(-2))
2394
+ local seen1 = ObservableSpy.new(list:ObserveAtIndex(-1))
2448
2395
 
2449
2396
  list:Add("x", 1.5)
2450
2397
  list:_testForceFireEvents()
2451
2398
 
2452
2399
  expect(list:GetList()).toEqual({ "a", "x", "b", "c" })
2453
- expect(seen4).toEqual({ NIL_VALUE, "a" })
2454
- expect(seen3).toEqual({ "a", "x" })
2455
- expect(seen2).toEqual({ "b" })
2456
- expect(seen1).toEqual({ "c" })
2457
-
2458
- sub4:Destroy()
2459
- sub3:Destroy()
2460
- sub2:Destroy()
2461
- sub1:Destroy()
2400
+ expect(#seen4).toEqual(2)
2401
+ expect(seen4[1]).toBeNil()
2402
+ expect(seen4[2]).toEqual("a")
2403
+ expect(#seen3).toEqual(2)
2404
+ expect(seen3.Values).toEqual({ "a", "x" })
2405
+ expect(#seen2).toEqual(1)
2406
+ expect(seen2.Values).toEqual({ "b" })
2407
+ expect(#seen1).toEqual(1)
2408
+ expect(seen1.Values).toEqual({ "c" })
2409
+
2410
+ seen4:Destroy()
2411
+ seen3:Destroy()
2412
+ seen2:Destroy()
2413
+ seen1:Destroy()
2462
2414
  maid:Destroy()
2463
2415
  end)
2464
2416
 
@@ -2470,21 +2422,25 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2470
2422
  list:Add("c", 3)
2471
2423
  list:_testForceFireEvents()
2472
2424
 
2473
- local seen3, sub3 = observe(list, -3)
2474
- local seen2, sub2 = observe(list, -2)
2475
- local seen1, sub1 = observe(list, -1)
2425
+ local seen3 = ObservableSpy.new(list:ObserveAtIndex(-3))
2426
+ local seen2 = ObservableSpy.new(list:ObserveAtIndex(-2))
2427
+ local seen1 = ObservableSpy.new(list:ObserveAtIndex(-1))
2476
2428
 
2477
2429
  removeB()
2478
2430
  list:_testForceFireEvents()
2479
2431
 
2480
2432
  expect(list:GetList()).toEqual({ "a", "c" })
2481
- expect(seen3).toEqual({ "a", NIL_VALUE })
2482
- expect(seen2).toEqual({ "b", "a" })
2483
- expect(seen1).toEqual({ "c" })
2484
-
2485
- sub3:Destroy()
2486
- sub2:Destroy()
2487
- sub1:Destroy()
2433
+ expect(#seen3).toEqual(2)
2434
+ expect(seen3[1]).toEqual("a")
2435
+ expect(seen3[2]).toBeNil()
2436
+ expect(#seen2).toEqual(2)
2437
+ expect(seen2.Values).toEqual({ "b", "a" })
2438
+ expect(#seen1).toEqual(1)
2439
+ expect(seen1.Values).toEqual({ "c" })
2440
+
2441
+ seen3:Destroy()
2442
+ seen2:Destroy()
2443
+ seen1:Destroy()
2488
2444
  maid:Destroy()
2489
2445
  end)
2490
2446
 
@@ -2496,14 +2452,15 @@ describe("ObservableSortedList negative index observation (mirrors ObservableLis
2496
2452
  list:Add("c", 3)
2497
2453
  list:_testForceFireEvents()
2498
2454
 
2499
- local seen, sub = observe(list, 2)
2455
+ local seen = ObservableSpy.new(list:ObserveAtIndex(2))
2500
2456
 
2501
2457
  removeA()
2502
2458
  list:_testForceFireEvents()
2503
2459
 
2504
- expect(seen).toEqual({ "b", "c" })
2460
+ expect(#seen).toEqual(2)
2461
+ expect(seen.Values).toEqual({ "b", "c" })
2505
2462
 
2506
- sub:Destroy()
2463
+ seen:Destroy()
2507
2464
  maid:Destroy()
2508
2465
  end)
2509
2466
 
@@ -2550,7 +2507,7 @@ describe("ObservableSortedList emission cost (mirrors ObservableList)", function
2550
2507
  it("fires a bounded number of observers per Add with a last-item observer", function()
2551
2508
  local maid = Maid.new()
2552
2509
  local list = maid:Add(ObservableSortedList.new())
2553
- local _, sub = observe(list, -1)
2510
+ local sub = list:ObserveAtIndex(-1):Subscribe()
2554
2511
 
2555
2512
  local fires = countFires(function()
2556
2513
  for i = 1, ITEMS do
@@ -2573,7 +2530,7 @@ describe("ObservableSortedList emission cost (mirrors ObservableList)", function
2573
2530
  removers[i] = list:Add(i, i)
2574
2531
  end
2575
2532
  list:_testForceFireEvents()
2576
- local _, sub = observe(list, -1)
2533
+ local sub = list:ObserveAtIndex(-1):Subscribe()
2577
2534
 
2578
2535
  local fires = countFires(function()
2579
2536
  for i = ITEMS, 1, -1 do