@quenty/observablecollection 12.10.0 → 12.10.1-canary.513.484c203.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.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.10.1-canary.513.484c203.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.10.0...@quenty/observablecollection@12.10.1-canary.513.484c203.0) (2024-10-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add __iter implementations ([b8e614a](https://github.com/Quenty/NevermoreEngine/commit/b8e614a8fda875c03237dc6cde18cf817beec0c4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Performance Improvements
|
|
15
|
+
|
|
16
|
+
* Use ObservableSubscriptionTable and stop debug validating integrity ([dbe74ba](https://github.com/Quenty/NevermoreEngine/commit/dbe74ba23b3b541f687999e22e60322fe11bbd2c))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [12.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.9.1...@quenty/observablecollection@12.10.0) (2024-10-23)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @quenty/observablecollection
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/observablecollection",
|
|
3
|
-
"version": "12.10.0",
|
|
3
|
+
"version": "12.10.1-canary.513.484c203.0",
|
|
4
4
|
"description": "A set of observable collections, such as sets, maps, sorted lists, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,23 +27,23 @@
|
|
|
27
27
|
"Quenty"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@quenty/baseobject": "
|
|
31
|
-
"@quenty/brio": "
|
|
32
|
-
"@quenty/ducktype": "
|
|
33
|
-
"@quenty/loader": "
|
|
34
|
-
"@quenty/maid": "
|
|
35
|
-
"@quenty/promise": "
|
|
36
|
-
"@quenty/rx": "
|
|
37
|
-
"@quenty/signal": "
|
|
38
|
-
"@quenty/steputils": "
|
|
39
|
-
"@quenty/symbol": "
|
|
40
|
-
"@quenty/valueobject": "
|
|
30
|
+
"@quenty/baseobject": "10.7.0",
|
|
31
|
+
"@quenty/brio": "14.10.1-canary.513.484c203.0",
|
|
32
|
+
"@quenty/ducktype": "5.7.0",
|
|
33
|
+
"@quenty/loader": "10.7.0",
|
|
34
|
+
"@quenty/maid": "3.4.0",
|
|
35
|
+
"@quenty/promise": "10.7.1-canary.513.484c203.0",
|
|
36
|
+
"@quenty/rx": "13.10.1-canary.513.484c203.0",
|
|
37
|
+
"@quenty/signal": "7.8.0",
|
|
38
|
+
"@quenty/steputils": "3.5.2",
|
|
39
|
+
"@quenty/symbol": "3.2.0",
|
|
40
|
+
"@quenty/valueobject": "13.10.1-canary.513.484c203.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@quenty/blend": "
|
|
43
|
+
"@quenty/blend": "12.10.1-canary.513.484c203.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "484c2031829caf7e983cae58a6aa6f0ceef1d059"
|
|
49
49
|
}
|
|
@@ -73,6 +73,15 @@ function ObservableCountingMap.isObservableMap(value)
|
|
|
73
73
|
return DuckTypeUtils.isImplementation(ObservableCountingMap, value)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
--[=[
|
|
77
|
+
Allows iteration over the observable counting map
|
|
78
|
+
|
|
79
|
+
@return (T) -> ((T, nextIndex: any) -> ...any, T?)
|
|
80
|
+
]=]
|
|
81
|
+
function ObservableCountingMap:__iter()
|
|
82
|
+
return pairs(self._map)
|
|
83
|
+
end
|
|
84
|
+
|
|
76
85
|
--[=[
|
|
77
86
|
Observes the current set of active keys
|
|
78
87
|
@return Observable<{ T }>
|
|
@@ -89,6 +89,19 @@ function ObservableList:Observe()
|
|
|
89
89
|
})
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
+
--[=[
|
|
93
|
+
Allows iteration over the observable map
|
|
94
|
+
|
|
95
|
+
@return (T) -> ((T, nextIndex: any) -> ...any, T?)
|
|
96
|
+
]=]
|
|
97
|
+
function ObservableList:__iter()
|
|
98
|
+
return coroutine.wrap(function()
|
|
99
|
+
for index, value in self._keyList do
|
|
100
|
+
coroutine.yield(index, self._contents[value])
|
|
101
|
+
end
|
|
102
|
+
end)
|
|
103
|
+
end
|
|
104
|
+
|
|
92
105
|
--[=[
|
|
93
106
|
Observes all items in the list
|
|
94
107
|
@return Observable<Brio<T>>
|
|
@@ -74,6 +74,16 @@ function ObservableMap.isObservableMap(value)
|
|
|
74
74
|
return DuckTypeUtils.isImplementation(ObservableMap, value)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
--[=[
|
|
78
|
+
Allows iteration over the observable map
|
|
79
|
+
|
|
80
|
+
@return (T) -> ((T, nextIndex: any) -> ...any, T?)
|
|
81
|
+
]=]
|
|
82
|
+
function ObservableMap:__iter()
|
|
83
|
+
return pairs(self._map)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
77
87
|
--[=[
|
|
78
88
|
Observes all keys in the map
|
|
79
89
|
@return Observable<Brio<TKey>>
|
|
@@ -65,6 +65,15 @@ function ObservableSet.isObservableSet(value)
|
|
|
65
65
|
return DuckTypeUtils.isImplementation(ObservableSet, value)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
--[=[
|
|
69
|
+
Allows iteration over the observable set
|
|
70
|
+
|
|
71
|
+
@return (T) -> ((T, nextIndex: any) -> ...any, T?)
|
|
72
|
+
]=]
|
|
73
|
+
function ObservableSet:__iter()
|
|
74
|
+
return pairs(self._set)
|
|
75
|
+
end
|
|
76
|
+
|
|
68
77
|
--[=[
|
|
69
78
|
Observes all items in the set
|
|
70
79
|
@return Observable<Brio<T>>
|
|
@@ -60,13 +60,12 @@ function ObservableSortedList.new(isReversed, compare)
|
|
|
60
60
|
|
|
61
61
|
self._indexObservers = self._maid:Add(ObservableSubscriptionTable.new())
|
|
62
62
|
self._contentIndexObservers = self._maid:Add(ObservableSubscriptionTable.new())
|
|
63
|
+
self._keyObservables = self._maid:Add(ObservableSubscriptionTable.new())
|
|
63
64
|
|
|
64
65
|
self._sortValue = {} -- { [Symbol]: number }
|
|
65
66
|
self._contents = {} -- { [Symbol]: T }
|
|
66
67
|
self._indexes = {} -- { [Symbol]: number }
|
|
67
68
|
|
|
68
|
-
self._keyObservables = {} -- { [Symbol]: { Subscription } }
|
|
69
|
-
|
|
70
69
|
self._isReversed = isReversed or false
|
|
71
70
|
self._compare = compare or defaultCompare
|
|
72
71
|
|
|
@@ -124,6 +123,19 @@ function ObservableSortedList:Observe()
|
|
|
124
123
|
})
|
|
125
124
|
end
|
|
126
125
|
|
|
126
|
+
--[=[
|
|
127
|
+
Allows iteration over the observable map
|
|
128
|
+
|
|
129
|
+
@return (T) -> ((T, nextIndex: any) -> ...any, T?)
|
|
130
|
+
]=]
|
|
131
|
+
function ObservableSortedList:__iter()
|
|
132
|
+
return coroutine.wrap(function()
|
|
133
|
+
for index, value in self._keyList do
|
|
134
|
+
coroutine.yield(index, self._contents[value])
|
|
135
|
+
end
|
|
136
|
+
end)
|
|
137
|
+
end
|
|
138
|
+
|
|
127
139
|
function ObservableSortedList:Contains(value)
|
|
128
140
|
-- TODO: Binary search
|
|
129
141
|
for _, item in pairs(self._contents) do
|
|
@@ -239,33 +251,16 @@ end
|
|
|
239
251
|
function ObservableSortedList:ObserveIndexByKey(key)
|
|
240
252
|
assert(Symbol.isSymbol(key), "Bad key")
|
|
241
253
|
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
sub:Fire(currentIndex)
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
maid:GiveTask(function()
|
|
253
|
-
local list = self._keyObservables[key]
|
|
254
|
-
if not list then
|
|
255
|
-
return
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
local index = table.find(list, sub)
|
|
259
|
-
if index then
|
|
260
|
-
table.remove(list, index)
|
|
261
|
-
if #list == 0 then
|
|
262
|
-
self._keyObservables[key] = nil
|
|
263
|
-
end
|
|
254
|
+
return self._keyObservables:Observe(key):Pipe({
|
|
255
|
+
Rx.startFrom(function()
|
|
256
|
+
local currentIndex = self._indexes[key]
|
|
257
|
+
if currentIndex then
|
|
258
|
+
return { currentIndex }
|
|
259
|
+
else
|
|
260
|
+
return {}
|
|
264
261
|
end
|
|
265
|
-
end)
|
|
266
|
-
|
|
267
|
-
return maid
|
|
268
|
-
end)
|
|
262
|
+
end);
|
|
263
|
+
})
|
|
269
264
|
end
|
|
270
265
|
|
|
271
266
|
--[=[
|
|
@@ -337,15 +332,10 @@ function ObservableSortedList:Add(item, observeValue)
|
|
|
337
332
|
end
|
|
338
333
|
|
|
339
334
|
maid:GiveTask(function()
|
|
340
|
-
local observableSubs = self._keyObservables[key]
|
|
341
|
-
self._keyObservables[key] = nil
|
|
342
|
-
|
|
343
335
|
self:_removeItemByKey(key, item)
|
|
344
336
|
|
|
345
337
|
-- Fire off the index change on the value
|
|
346
|
-
|
|
347
|
-
self:_completeSubs(observableSubs)
|
|
348
|
-
end
|
|
338
|
+
self._keyObservables:Complete(key)
|
|
349
339
|
|
|
350
340
|
self._contents[key] = nil
|
|
351
341
|
self._sortValue[key] = nil
|
|
@@ -359,7 +349,7 @@ function ObservableSortedList:Add(item, observeValue)
|
|
|
359
349
|
end
|
|
360
350
|
|
|
361
351
|
function ObservableSortedList:_assignSortValue(key, item, sortValue)
|
|
362
|
-
self:_debugVerifyIntegrity()
|
|
352
|
+
-- self:_debugVerifyIntegrity()
|
|
363
353
|
|
|
364
354
|
if sortValue ~= nil then
|
|
365
355
|
local currentIndex = self._indexes[key]
|
|
@@ -368,18 +358,12 @@ function ObservableSortedList:_assignSortValue(key, item, sortValue)
|
|
|
368
358
|
self._sortValue[key] = sortValue
|
|
369
359
|
self:_updateIndex(key, item, targetIndex, sortValue)
|
|
370
360
|
else
|
|
371
|
-
local observableSubs = self._keyObservables[key]
|
|
372
|
-
|
|
373
361
|
-- calling this also may unsubscribe some observables.
|
|
374
362
|
self:_removeItemByKey(key, item)
|
|
375
|
-
|
|
376
|
-
if observableSubs then
|
|
377
|
-
-- fire nil index
|
|
378
|
-
self:_fireSubs(observableSubs, nil)
|
|
379
|
-
end
|
|
363
|
+
self._keyObservables:Complete(key)
|
|
380
364
|
end
|
|
381
365
|
|
|
382
|
-
self:_debugVerifyIntegrity()
|
|
366
|
+
-- self:_debugVerifyIntegrity()
|
|
383
367
|
end
|
|
384
368
|
|
|
385
369
|
|
|
@@ -596,11 +580,7 @@ function ObservableSortedList:_queueDeferredChange()
|
|
|
596
580
|
if self._indexes[lastChange.key] == lastChange.newIndex then
|
|
597
581
|
changed = true
|
|
598
582
|
|
|
599
|
-
|
|
600
|
-
if subs then
|
|
601
|
-
self:_fireSubs(subs, lastChange.newIndex)
|
|
602
|
-
end
|
|
603
|
-
|
|
583
|
+
self._keyObservables:Fire(lastChange.key, lastChange.newIndex)
|
|
604
584
|
self._indexObservers:Fire(lastChange.newIndex, self._contents[lastChange.key])
|
|
605
585
|
end
|
|
606
586
|
end
|
|
@@ -682,7 +662,9 @@ function ObservableSortedList:_lowBinarySearch(sortValue)
|
|
|
682
662
|
while true do
|
|
683
663
|
local mid = math.floor((minIndex + maxIndex) / 2)
|
|
684
664
|
local compareValue = self._compare(self._sortValue[self._keyList[mid]], sortValue)
|
|
685
|
-
|
|
665
|
+
if type(compareValue) ~= "number" then
|
|
666
|
+
error(string.format("Bad compareValue, expected number, got %q", type(compareValue)))
|
|
667
|
+
end
|
|
686
668
|
|
|
687
669
|
if self._isReversed then
|
|
688
670
|
compareValue = -compareValue
|
|
@@ -702,16 +684,6 @@ function ObservableSortedList:_lowBinarySearch(sortValue)
|
|
|
702
684
|
end
|
|
703
685
|
end
|
|
704
686
|
|
|
705
|
-
function ObservableSortedList:_debugSortValuesToString()
|
|
706
|
-
local values = {}
|
|
707
|
-
|
|
708
|
-
for _, key in pairs(self._keyList) do
|
|
709
|
-
table.insert(values, string.format("%4d", self._sortValue[key]))
|
|
710
|
-
end
|
|
711
|
-
|
|
712
|
-
return table.concat(values, ", ")
|
|
713
|
-
end
|
|
714
|
-
|
|
715
687
|
function ObservableSortedList:_debugVerifyIntegrity()
|
|
716
688
|
for i=2, #self._keyList do
|
|
717
689
|
local compare = self._compare(self._sortValue[self._keyList[i-1]], self._sortValue[self._keyList[i]])
|
|
@@ -730,23 +702,14 @@ function ObservableSortedList:_debugVerifyIntegrity()
|
|
|
730
702
|
end
|
|
731
703
|
end
|
|
732
704
|
|
|
733
|
-
function ObservableSortedList:
|
|
734
|
-
|
|
735
|
-
if sub:IsPending() then
|
|
736
|
-
task.spawn(function()
|
|
737
|
-
sub:Fire(index)
|
|
738
|
-
end)
|
|
739
|
-
end
|
|
740
|
-
end
|
|
741
|
-
end
|
|
705
|
+
function ObservableSortedList:_debugSortValuesToString()
|
|
706
|
+
local values = {}
|
|
742
707
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
if sub:IsPending() then
|
|
746
|
-
sub:Fire(nil)
|
|
747
|
-
sub:Complete()
|
|
748
|
-
end
|
|
708
|
+
for _, key in pairs(self._keyList) do
|
|
709
|
+
table.insert(values, string.format("%4d", self._sortValue[key]))
|
|
749
710
|
end
|
|
711
|
+
|
|
712
|
+
return table.concat(values, ", ")
|
|
750
713
|
end
|
|
751
714
|
|
|
752
715
|
--[=[
|