@quenty/observablecollection 12.54.1 → 12.55.1
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.
- package/CHANGELOG.md +10 -0
- package/package.json +14 -14
- package/src/Shared/ObservableCountingMap.lua +16 -6
- package/src/Shared/ObservableCountingMap.spec.lua +114 -0
- package/src/Shared/ObservableList.spec.lua +103 -138
- package/src/Shared/ObservableMap.lua +11 -4
- package/src/Shared/ObservableMap.spec.lua +81 -12
- package/src/Shared/ObservableSet.lua +5 -2
- package/src/Shared/ObservableSet.spec.lua +86 -0
- package/src/Shared/SortedList/ObservableSortedList.spec.lua +253 -296
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class ObservableSet.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local Jest = require("Jest")
|
|
9
|
+
local Maid = require("Maid")
|
|
10
|
+
local ObservableSet = require("ObservableSet")
|
|
11
|
+
|
|
12
|
+
local describe = Jest.Globals.describe
|
|
13
|
+
local expect = Jest.Globals.expect
|
|
14
|
+
local it = Jest.Globals.it
|
|
15
|
+
|
|
16
|
+
-- The skip depends on where items hash, so one walk rarely shows it
|
|
17
|
+
local TRIALS = 100
|
|
18
|
+
|
|
19
|
+
type Controller = {
|
|
20
|
+
newSetWithItems: (count: number) -> (ObservableSet.ObservableSet<any>, { any }),
|
|
21
|
+
Destroy: (self: Controller) -> (),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
local function setup(): Controller
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local controller: Controller = {
|
|
28
|
+
newSetWithItems = function(count)
|
|
29
|
+
local set = maid:Add(ObservableSet.new())
|
|
30
|
+
local items = {}
|
|
31
|
+
for _ = 1, count do
|
|
32
|
+
local item = {}
|
|
33
|
+
table.insert(items, item)
|
|
34
|
+
set:Add(item)
|
|
35
|
+
end
|
|
36
|
+
return set, items
|
|
37
|
+
end,
|
|
38
|
+
|
|
39
|
+
Destroy = function(_self)
|
|
40
|
+
maid:DoCleaning()
|
|
41
|
+
end,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return controller
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe("ObservableSet.ObserveItemsBrio", function()
|
|
48
|
+
it("emits every existing item when the subscriber adds items", function()
|
|
49
|
+
local controller = setup()
|
|
50
|
+
|
|
51
|
+
for _ = 1, TRIALS do
|
|
52
|
+
local set, items = controller.newSetWithItems(5)
|
|
53
|
+
local seen = {}
|
|
54
|
+
set:ObserveItemsBrio():Subscribe(function(brio)
|
|
55
|
+
local item = brio:GetValue()
|
|
56
|
+
if table.find(items, item) then
|
|
57
|
+
table.insert(seen, item)
|
|
58
|
+
for _ = 1, 3 do
|
|
59
|
+
set:Add({})
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end)
|
|
63
|
+
|
|
64
|
+
expect(#seen).toBe(#items)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
controller:Destroy()
|
|
68
|
+
end)
|
|
69
|
+
|
|
70
|
+
it("skips an item the subscriber removes before the walk reaches it", function()
|
|
71
|
+
local controller = setup()
|
|
72
|
+
local set, items = controller.newSetWithItems(5)
|
|
73
|
+
|
|
74
|
+
local seen = {}
|
|
75
|
+
set:ObserveItemsBrio():Subscribe(function(brio)
|
|
76
|
+
table.insert(seen, brio:GetValue())
|
|
77
|
+
for _, item in items do
|
|
78
|
+
set:Remove(item)
|
|
79
|
+
end
|
|
80
|
+
end)
|
|
81
|
+
|
|
82
|
+
expect(#seen).toBe(1)
|
|
83
|
+
|
|
84
|
+
controller:Destroy()
|
|
85
|
+
end)
|
|
86
|
+
end)
|