@quenty/observablecollection 12.8.1 → 12.9.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,29 @@
|
|
|
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.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.8.1...@quenty/observablecollection@12.9.0) (2024-10-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add ObservableMapSet:GetKeyList() ([e5d3461](https://github.com/Quenty/NevermoreEngine/commit/e5d3461e5f835c9442e49eb0f304dc5fb360cb28))
|
|
12
|
+
* Brios sometime cleanup wrongly ([e546588](https://github.com/Quenty/NevermoreEngine/commit/e546588d97b2e8f8386d9795f04929c9b45a27d1))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Add ObservableMapList:GetFirstItemForKey(key) and ObservableMapList:GetListOfValuesAtListIndex(index) ([bdfc759](https://github.com/Quenty/NevermoreEngine/commit/bdfc7596d8e25350e65a3cc841debcfa0ad444de))
|
|
18
|
+
* Add ObservableMapList:GetItemForKeyAtIndex(key, index) ([224dd25](https://github.com/Quenty/NevermoreEngine/commit/224dd250f2794b7f584d756828dffd9e49b0d009))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Performance Improvements
|
|
22
|
+
|
|
23
|
+
* Improve :GetKeyList() allocation performance ([b8043cf](https://github.com/Quenty/NevermoreEngine/commit/b8043cfad4e4cfdb2c8ec5d73988bb8bae723c42))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
## [12.8.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.8.0...@quenty/observablecollection@12.8.1) (2024-10-04)
|
|
7
30
|
|
|
8
31
|
**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.
|
|
3
|
+
"version": "12.9.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": "^10.
|
|
31
|
-
"@quenty/brio": "^14.
|
|
32
|
-
"@quenty/ducktype": "^5.
|
|
33
|
-
"@quenty/loader": "^10.
|
|
30
|
+
"@quenty/baseobject": "^10.7.0",
|
|
31
|
+
"@quenty/brio": "^14.9.0",
|
|
32
|
+
"@quenty/ducktype": "^5.7.0",
|
|
33
|
+
"@quenty/loader": "^10.7.0",
|
|
34
34
|
"@quenty/maid": "^3.4.0",
|
|
35
|
-
"@quenty/promise": "^10.
|
|
36
|
-
"@quenty/rx": "^13.
|
|
37
|
-
"@quenty/signal": "^7.
|
|
35
|
+
"@quenty/promise": "^10.7.0",
|
|
36
|
+
"@quenty/rx": "^13.9.0",
|
|
37
|
+
"@quenty/signal": "^7.8.0",
|
|
38
38
|
"@quenty/steputils": "^3.5.1",
|
|
39
39
|
"@quenty/symbol": "^3.2.0",
|
|
40
|
-
"@quenty/valueobject": "^13.
|
|
40
|
+
"@quenty/valueobject": "^13.9.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@quenty/blend": "^12.
|
|
43
|
+
"@quenty/blend": "^12.9.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "67c5dbf46f6f45213812f3f117419a5534936a0b"
|
|
49
49
|
}
|
|
@@ -79,7 +79,7 @@ end
|
|
|
79
79
|
]=]
|
|
80
80
|
function ObservableCountingMap:ObserveKeysList()
|
|
81
81
|
return self:_observeDerivedDataStructureFromKeys(function()
|
|
82
|
-
local list =
|
|
82
|
+
local list = table.create(self._totalKeyCountValue.Value)
|
|
83
83
|
|
|
84
84
|
for key, _ in pairs(self._map) do
|
|
85
85
|
table.insert(list, key)
|
|
@@ -184,22 +184,28 @@ end
|
|
|
184
184
|
function ObservableCountingMap:ObserveKeysBrio()
|
|
185
185
|
return Observable.new(function(sub)
|
|
186
186
|
local maid = Maid.new()
|
|
187
|
+
local keyMaid = maid:Add(Maid.new())
|
|
187
188
|
|
|
188
189
|
local function handleItem(key)
|
|
190
|
+
-- Happens upon key added re-entrance
|
|
191
|
+
if keyMaid[key] then
|
|
192
|
+
return
|
|
193
|
+
end
|
|
194
|
+
|
|
189
195
|
local brio = Brio.new(key)
|
|
190
|
-
|
|
196
|
+
keyMaid[key] = brio
|
|
191
197
|
sub:Fire(brio)
|
|
192
198
|
end
|
|
193
199
|
|
|
194
|
-
for key, _ in pairs(self._map) do
|
|
195
|
-
handleItem(key)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
200
|
maid:GiveTask(self.KeyAdded:Connect(handleItem))
|
|
199
201
|
maid:GiveTask(self.KeyRemoved:Connect(function(key)
|
|
200
|
-
|
|
202
|
+
keyMaid[key] = nil
|
|
201
203
|
end))
|
|
202
204
|
|
|
205
|
+
for key, _ in pairs(self._map) do
|
|
206
|
+
handleItem(key)
|
|
207
|
+
end
|
|
208
|
+
|
|
203
209
|
self._maid[sub] = maid
|
|
204
210
|
maid:GiveTask(function()
|
|
205
211
|
self._maid[sub] = nil
|
|
@@ -286,8 +292,10 @@ function ObservableCountingMap:Add(key, amount)
|
|
|
286
292
|
return
|
|
287
293
|
end
|
|
288
294
|
|
|
289
|
-
|
|
290
|
-
|
|
295
|
+
local oldValue = self._map[key]
|
|
296
|
+
|
|
297
|
+
if oldValue then
|
|
298
|
+
local newValue = oldValue + amount
|
|
291
299
|
if newValue == 0 then
|
|
292
300
|
-- Remove item
|
|
293
301
|
self._map[key] = nil
|
|
@@ -363,7 +371,7 @@ end
|
|
|
363
371
|
@return { T }
|
|
364
372
|
]=]
|
|
365
373
|
function ObservableCountingMap:GetKeyList()
|
|
366
|
-
local list =
|
|
374
|
+
local list = table.create(self._totalKeyCountValue.Value)
|
|
367
375
|
for key, _ in pairs(self._map) do
|
|
368
376
|
table.insert(list, key)
|
|
369
377
|
end
|
|
@@ -144,6 +144,11 @@ end
|
|
|
144
144
|
Observes the current value at a given index. This can be useful for observing
|
|
145
145
|
the first entry, or matching stuff up to a given slot.
|
|
146
146
|
|
|
147
|
+
```
|
|
148
|
+
list:ObserveAtIndex(1):Subscribe(print) --> prints first item
|
|
149
|
+
list:ObserveAtIndex(-1):Subscribe(print) --> prints last item
|
|
150
|
+
```
|
|
151
|
+
|
|
147
152
|
@param indexToObserve number
|
|
148
153
|
@return Observable<T?>
|
|
149
154
|
]=]
|
|
@@ -92,8 +92,54 @@ function ObservableMapList:Push(observeKey, entry)
|
|
|
92
92
|
return maid
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
--[=[
|
|
96
|
+
Gets the first item for the given key
|
|
97
|
+
|
|
98
|
+
@param key TKey
|
|
99
|
+
@return TValue | nil
|
|
100
|
+
]=]
|
|
101
|
+
function ObservableMapList:GetFirstItemForKey(key)
|
|
102
|
+
assert(key ~= nil, "Bad key")
|
|
103
|
+
|
|
104
|
+
local observableList = self:GetListForKey(key)
|
|
105
|
+
if not observableList then
|
|
106
|
+
return nil
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
return observableList:Get(1)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
--[=[
|
|
113
|
+
Gets the item for the given key at the index
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
mapList:Push("fruits", "apple")
|
|
117
|
+
mapList:Push("fruits", "orange")
|
|
118
|
+
mapList:Push("fruits", "banana")
|
|
119
|
+
|
|
120
|
+
-- Print the last item
|
|
121
|
+
print(mapList:GetItemForKeyAtIndex("fruits", -1)) ==> banana
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
@param key TKey
|
|
125
|
+
@param index number
|
|
126
|
+
@return TValue | nil
|
|
127
|
+
]=]
|
|
128
|
+
function ObservableMapList:GetItemForKeyAtIndex(key, index)
|
|
129
|
+
assert(key ~= nil, "Bad key")
|
|
130
|
+
assert(type(index) == "number", "Bad index")
|
|
131
|
+
|
|
132
|
+
local observableList = self:GetListForKey(key)
|
|
133
|
+
if not observableList then
|
|
134
|
+
return nil
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
return observableList:Get(index)
|
|
138
|
+
end
|
|
139
|
+
|
|
95
140
|
--[=[
|
|
96
141
|
Gets how many lists exist
|
|
142
|
+
|
|
97
143
|
@return number
|
|
98
144
|
]=]
|
|
99
145
|
function ObservableMapList:GetListCount()
|
|
@@ -102,6 +148,7 @@ end
|
|
|
102
148
|
|
|
103
149
|
--[=[
|
|
104
150
|
Observes how many lists exist
|
|
151
|
+
|
|
105
152
|
@return Observable<number>
|
|
106
153
|
]=]
|
|
107
154
|
function ObservableMapList:ObserveListCount()
|
|
@@ -244,6 +291,27 @@ function ObservableMapList:GetListForKey(key)
|
|
|
244
291
|
return self._observableMapOfLists:Get(key)
|
|
245
292
|
end
|
|
246
293
|
|
|
294
|
+
--[=[
|
|
295
|
+
Gets a list of all of the entries at the given index, if it exists
|
|
296
|
+
|
|
297
|
+
@param index number
|
|
298
|
+
@return ObservableList<TValue>
|
|
299
|
+
]=]
|
|
300
|
+
function ObservableMapList:GetListOfValuesAtListIndex(index)
|
|
301
|
+
assert(type(index) == "number", "Bad index")
|
|
302
|
+
|
|
303
|
+
local list = table.create(self._observableMapOfLists:GetCount())
|
|
304
|
+
|
|
305
|
+
for _, observableList in pairs(self._observableMapOfLists:GetValueList()) do
|
|
306
|
+
local value = observableList:Get(index)
|
|
307
|
+
if value ~= nil then
|
|
308
|
+
table.insert(list, value)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
return list
|
|
313
|
+
end
|
|
314
|
+
|
|
247
315
|
--[=[
|
|
248
316
|
Observes the observable list for the given key
|
|
249
317
|
|
|
@@ -78,20 +78,26 @@ function ObservableSet:ObserveItemsBrio()
|
|
|
78
78
|
local maid = Maid.new()
|
|
79
79
|
|
|
80
80
|
local function handleItem(item)
|
|
81
|
+
if maid[item] then
|
|
82
|
+
-- Happens when we're re-entrance
|
|
83
|
+
return
|
|
84
|
+
end
|
|
85
|
+
|
|
81
86
|
local brio = Brio.new(item)
|
|
82
87
|
maid[item] = brio
|
|
83
88
|
sub:Fire(brio)
|
|
84
89
|
end
|
|
85
90
|
|
|
86
|
-
for item, _ in pairs(self._set) do
|
|
87
|
-
handleItem(item)
|
|
88
|
-
end
|
|
89
91
|
|
|
90
92
|
maid:GiveTask(self.ItemAdded:Connect(handleItem))
|
|
91
93
|
maid:GiveTask(self.ItemRemoved:Connect(function(item)
|
|
92
94
|
maid[item] = nil
|
|
93
95
|
end))
|
|
94
96
|
|
|
97
|
+
for item, _ in pairs(self._set) do
|
|
98
|
+
handleItem(item)
|
|
99
|
+
end
|
|
100
|
+
|
|
95
101
|
self._maid[sub] = maid
|
|
96
102
|
maid:GiveTask(function()
|
|
97
103
|
self._maid[sub] = nil
|