@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [12.55.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.55.0...@quenty/observablecollection@12.55.1) (2026-11-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/observablecollection
|
|
9
|
+
|
|
10
|
+
# [12.55.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.54.1...@quenty/observablecollection@12.55.0) (2026-10-24)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- **observablecollection:** Emit every existing key when a subscriber adds keys ([6d8859d](https://github.com/Quenty/NevermoreEngine/commit/6d8859dda5fed71922c1d18b66a6e1a304537498))
|
|
15
|
+
|
|
6
16
|
## [12.54.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.54.0...@quenty/observablecollection@12.54.1) (2026-10-20)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/observablecollection",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.55.1",
|
|
4
4
|
"description": "A set of observable collections, such as sets, maps, sorted lists, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -30,28 +30,28 @@
|
|
|
30
30
|
"Quenty"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@quenty/baseobject": "10.16.
|
|
33
|
+
"@quenty/baseobject": "10.16.4",
|
|
34
34
|
"@quenty/binarysearch": "2.4.0",
|
|
35
|
-
"@quenty/brio": "14.38.
|
|
35
|
+
"@quenty/brio": "14.38.2",
|
|
36
36
|
"@quenty/ducktype": "5.11.3",
|
|
37
|
-
"@quenty/instanceutils": "13.38.
|
|
37
|
+
"@quenty/instanceutils": "13.38.2",
|
|
38
38
|
"@quenty/loader": "10.11.3",
|
|
39
|
-
"@quenty/maid": "3.12.
|
|
40
|
-
"@quenty/nevermore-test-runner": "1.6.
|
|
41
|
-
"@quenty/promise": "10.25.
|
|
42
|
-
"@quenty/rx": "13.35.
|
|
43
|
-
"@quenty/signal": "7.13.
|
|
44
|
-
"@quenty/steputils": "3.9.
|
|
39
|
+
"@quenty/maid": "3.12.4",
|
|
40
|
+
"@quenty/nevermore-test-runner": "1.6.4",
|
|
41
|
+
"@quenty/promise": "10.25.2",
|
|
42
|
+
"@quenty/rx": "13.35.2",
|
|
43
|
+
"@quenty/signal": "7.13.5",
|
|
44
|
+
"@quenty/steputils": "3.9.4",
|
|
45
45
|
"@quenty/symbol": "3.5.2",
|
|
46
46
|
"@quenty/table": "3.9.2",
|
|
47
|
-
"@quenty/valueobject": "13.39.
|
|
48
|
-
"@quentystudios/jest-lua": "3.10.0-quenty.
|
|
47
|
+
"@quenty/valueobject": "13.39.2",
|
|
48
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@quenty/blend": "12.51.
|
|
51
|
+
"@quenty/blend": "12.51.2"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f51b2de38a02f8d92758da8d381a378e760170aa"
|
|
57
57
|
}
|
|
@@ -167,23 +167,30 @@ function ObservableCountingMap.ObservePairsBrio<T>(
|
|
|
167
167
|
return Observable.new(function(sub)
|
|
168
168
|
local maid = Maid.new()
|
|
169
169
|
local keyMaid: any = maid:Add(Maid.new())
|
|
170
|
+
local emittedKeys: { [T]: true } = {}
|
|
170
171
|
|
|
171
172
|
local function handleValue(key: T, value: number)
|
|
172
173
|
if value ~= 0 then
|
|
173
174
|
local brio = Brio.new(key, value)
|
|
175
|
+
emittedKeys[key] = true
|
|
174
176
|
keyMaid[key] = brio
|
|
175
177
|
sub:Fire(brio)
|
|
176
178
|
else
|
|
179
|
+
emittedKeys[key] = nil
|
|
177
180
|
keyMaid[key] = nil
|
|
178
181
|
end
|
|
179
182
|
end
|
|
180
183
|
|
|
181
|
-
for key, value in self._map do
|
|
182
|
-
handleValue(key, value)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
184
|
maid:GiveTask(self.KeyChanged:Connect(handleValue))
|
|
186
185
|
|
|
186
|
+
-- Walk a snapshot: inserting keys during a table walk can skip existing ones
|
|
187
|
+
for key in table.clone(self._map) do
|
|
188
|
+
local value = self._map[key]
|
|
189
|
+
if value ~= nil and not emittedKeys[key] then
|
|
190
|
+
handleValue(key, value)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
187
194
|
self._maid[sub] = maid
|
|
188
195
|
maid:GiveTask(function()
|
|
189
196
|
self._maid[sub] = nil
|
|
@@ -233,8 +240,11 @@ function ObservableCountingMap.ObserveKeysBrio<T>(self: ObservableCountingMap<T>
|
|
|
233
240
|
keyMaid[key] = nil
|
|
234
241
|
end))
|
|
235
242
|
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
-- Walk a snapshot: inserting keys during a table walk can skip existing ones
|
|
244
|
+
for key in table.clone(self._map) do
|
|
245
|
+
if self._map[key] ~= nil then
|
|
246
|
+
handleItem(key)
|
|
247
|
+
end
|
|
238
248
|
end
|
|
239
249
|
|
|
240
250
|
self._maid[sub] = maid
|
|
@@ -6,12 +6,44 @@
|
|
|
6
6
|
local require = require(script.Parent.loader).load(script)
|
|
7
7
|
|
|
8
8
|
local Jest = require("Jest")
|
|
9
|
+
local Maid = require("Maid")
|
|
9
10
|
local ObservableCountingMap = require("ObservableCountingMap")
|
|
10
11
|
|
|
11
12
|
local describe = Jest.Globals.describe
|
|
12
13
|
local expect = Jest.Globals.expect
|
|
13
14
|
local it = Jest.Globals.it
|
|
14
15
|
|
|
16
|
+
-- The skip depends on where keys hash, so one walk rarely shows it
|
|
17
|
+
local TRIALS = 100
|
|
18
|
+
|
|
19
|
+
type Controller = {
|
|
20
|
+
newMapWithKeys: (count: number) -> (ObservableCountingMap.ObservableCountingMap<any>, { any }),
|
|
21
|
+
Destroy: (self: Controller) -> (),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
local function setup(): Controller
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local controller: Controller = {
|
|
28
|
+
newMapWithKeys = function(count)
|
|
29
|
+
local map = maid:Add(ObservableCountingMap.new())
|
|
30
|
+
local keys = {}
|
|
31
|
+
for _ = 1, count do
|
|
32
|
+
local key = {}
|
|
33
|
+
table.insert(keys, key)
|
|
34
|
+
map:Add(key)
|
|
35
|
+
end
|
|
36
|
+
return map, keys
|
|
37
|
+
end,
|
|
38
|
+
|
|
39
|
+
Destroy = function(_self)
|
|
40
|
+
maid:DoCleaning()
|
|
41
|
+
end,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return controller
|
|
45
|
+
end
|
|
46
|
+
|
|
15
47
|
describe("ObservableCountingMap.new()", function()
|
|
16
48
|
local observableCountingMap = ObservableCountingMap.new()
|
|
17
49
|
|
|
@@ -40,3 +72,85 @@ describe("ObservableCountingMap.new()", function()
|
|
|
40
72
|
observableCountingMap:Destroy()
|
|
41
73
|
end)
|
|
42
74
|
end)
|
|
75
|
+
|
|
76
|
+
describe("ObservableCountingMap.ObserveKeysBrio", function()
|
|
77
|
+
it("emits every existing key when the subscriber adds keys", function()
|
|
78
|
+
local controller = setup()
|
|
79
|
+
|
|
80
|
+
for _ = 1, TRIALS do
|
|
81
|
+
local map, keys = controller.newMapWithKeys(5)
|
|
82
|
+
local seen = {}
|
|
83
|
+
map:ObserveKeysBrio():Subscribe(function(brio)
|
|
84
|
+
local key = brio:GetValue()
|
|
85
|
+
if table.find(keys, key) then
|
|
86
|
+
table.insert(seen, key)
|
|
87
|
+
for _ = 1, 3 do
|
|
88
|
+
map:Add({})
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end)
|
|
92
|
+
|
|
93
|
+
expect(#seen).toBe(#keys)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
controller:Destroy()
|
|
97
|
+
end)
|
|
98
|
+
|
|
99
|
+
it("skips a key the subscriber removes before the walk reaches it", function()
|
|
100
|
+
local controller = setup()
|
|
101
|
+
local map, keys = controller.newMapWithKeys(5)
|
|
102
|
+
|
|
103
|
+
local seen = {}
|
|
104
|
+
map:ObserveKeysBrio():Subscribe(function(brio)
|
|
105
|
+
table.insert(seen, brio:GetValue())
|
|
106
|
+
for _, key in keys do
|
|
107
|
+
map:Remove(key)
|
|
108
|
+
end
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
expect(#seen).toBe(1)
|
|
112
|
+
|
|
113
|
+
controller:Destroy()
|
|
114
|
+
end)
|
|
115
|
+
end)
|
|
116
|
+
|
|
117
|
+
describe("ObservableCountingMap.ObservePairsBrio", function()
|
|
118
|
+
it("emits every existing key when the subscriber adds keys", function()
|
|
119
|
+
local controller = setup()
|
|
120
|
+
|
|
121
|
+
for _ = 1, TRIALS do
|
|
122
|
+
local map, keys = controller.newMapWithKeys(5)
|
|
123
|
+
local seen = {}
|
|
124
|
+
map:ObservePairsBrio():Subscribe(function(brio)
|
|
125
|
+
local key = brio:GetValue()
|
|
126
|
+
if table.find(keys, key) then
|
|
127
|
+
table.insert(seen, key)
|
|
128
|
+
for _ = 1, 3 do
|
|
129
|
+
map:Add({})
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end)
|
|
133
|
+
|
|
134
|
+
expect(#seen).toBe(#keys)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
controller:Destroy()
|
|
138
|
+
end)
|
|
139
|
+
|
|
140
|
+
it("skips a key the subscriber removes before the walk reaches it", function()
|
|
141
|
+
local controller = setup()
|
|
142
|
+
local map, keys = controller.newMapWithKeys(5)
|
|
143
|
+
|
|
144
|
+
local seen = {}
|
|
145
|
+
map:ObservePairsBrio():Subscribe(function(brio)
|
|
146
|
+
table.insert(seen, (brio:GetValue()))
|
|
147
|
+
for _, key in keys do
|
|
148
|
+
map:Remove(key)
|
|
149
|
+
end
|
|
150
|
+
end)
|
|
151
|
+
|
|
152
|
+
expect(#seen).toBe(1)
|
|
153
|
+
|
|
154
|
+
controller:Destroy()
|
|
155
|
+
end)
|
|
156
|
+
end)
|