@quenty/observablecollection 12.3.1 → 12.4.0-canary.490.601c967.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 +3 -3
- package/package.json +14 -14
- package/src/Shared/ObservableCountingMap.lua +55 -1
- package/src/Shared/ObservableMap.lua +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
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
|
-
|
|
6
|
+
# [12.4.0-canary.490.601c967.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.3.0...@quenty/observablecollection@12.4.0-canary.490.601c967.0) (2024-08-27)
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
###
|
|
9
|
+
### Features
|
|
10
10
|
|
|
11
|
-
*
|
|
11
|
+
* Add ObservableCountingMap:ObservePairsBrio() and ObservableCountingMap:ObserveAtKey(key) ([b3baa09](https://github.com/Quenty/NevermoreEngine/commit/b3baa09563be96ccfd985496e833ad87a78bc953))
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/observablecollection",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.4.0-canary.490.601c967.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.4.0-canary.490.601c967.0",
|
|
31
|
+
"@quenty/brio": "14.4.0-canary.490.601c967.0",
|
|
32
|
+
"@quenty/ducktype": "5.4.0-canary.490.601c967.0",
|
|
33
|
+
"@quenty/loader": "10.4.0-canary.490.601c967.0",
|
|
34
|
+
"@quenty/maid": "3.2.0",
|
|
35
|
+
"@quenty/promise": "10.4.0-canary.490.601c967.0",
|
|
36
|
+
"@quenty/rx": "13.4.0-canary.490.601c967.0",
|
|
37
|
+
"@quenty/signal": "7.4.0-canary.490.601c967.0",
|
|
38
|
+
"@quenty/steputils": "3.4.0",
|
|
39
|
+
"@quenty/symbol": "3.1.0",
|
|
40
|
+
"@quenty/valueobject": "13.4.0-canary.490.601c967.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@quenty/blend": "
|
|
43
|
+
"@quenty/blend": "12.4.0-canary.490.601c967.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "601c9671f09638be4f326e41fcfe3343ccfe76d8"
|
|
49
49
|
}
|
|
@@ -11,6 +11,7 @@ local Maid = require("Maid")
|
|
|
11
11
|
local Brio = require("Brio")
|
|
12
12
|
local ValueObject = require("ValueObject")
|
|
13
13
|
local DuckTypeUtils = require("DuckTypeUtils")
|
|
14
|
+
local ObservableSubscriptionTable = require("ObservableSubscriptionTable")
|
|
14
15
|
|
|
15
16
|
local ObservableCountingMap = {}
|
|
16
17
|
ObservableCountingMap.ClassName = "ObservableCountingMap"
|
|
@@ -27,6 +28,7 @@ function ObservableCountingMap.new()
|
|
|
27
28
|
self._map = {}
|
|
28
29
|
|
|
29
30
|
self._totalKeyCountValue = self._maid:Add(ValueObject.new(0, "number"))
|
|
31
|
+
self._keySubTable = self._maid:Add(ObservableSubscriptionTable.new())
|
|
30
32
|
|
|
31
33
|
--[=[
|
|
32
34
|
Fires when an key is added
|
|
@@ -104,7 +106,7 @@ function ObservableCountingMap:ObserveKeysSet()
|
|
|
104
106
|
end
|
|
105
107
|
|
|
106
108
|
function ObservableCountingMap:_observeDerivedDataStructureFromKeys(gatherValues)
|
|
107
|
-
|
|
109
|
+
return Observable.new(function(sub)
|
|
108
110
|
local maid = Maid.new()
|
|
109
111
|
|
|
110
112
|
local function emit()
|
|
@@ -126,6 +128,55 @@ function ObservableCountingMap:_observeDerivedDataStructureFromKeys(gatherValues
|
|
|
126
128
|
end)
|
|
127
129
|
end
|
|
128
130
|
|
|
131
|
+
--[=[
|
|
132
|
+
Observes all keys in the map
|
|
133
|
+
@return Observable<Brio<(T, number)>>
|
|
134
|
+
]=]
|
|
135
|
+
function ObservableCountingMap:ObservePairsBrio()
|
|
136
|
+
return Observable.new(function(sub)
|
|
137
|
+
local maid = Maid.new()
|
|
138
|
+
|
|
139
|
+
local function handleValue(key, value)
|
|
140
|
+
if value ~= 0 then
|
|
141
|
+
local brio = Brio.new(key, value)
|
|
142
|
+
maid[key] = brio
|
|
143
|
+
sub:Fire(brio)
|
|
144
|
+
else
|
|
145
|
+
maid[key] = nil
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
for key, value in pairs(self._map) do
|
|
150
|
+
handleValue(key, value)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
maid:GiveTask(self.KeyChanged:Connect(handleValue))
|
|
154
|
+
|
|
155
|
+
self._maid[sub] = maid
|
|
156
|
+
maid:GiveTask(function()
|
|
157
|
+
self._maid[sub] = nil
|
|
158
|
+
sub:Complete()
|
|
159
|
+
end)
|
|
160
|
+
|
|
161
|
+
return maid
|
|
162
|
+
|
|
163
|
+
end)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
--[=[
|
|
167
|
+
Observes the value for the given key.
|
|
168
|
+
|
|
169
|
+
@param key TKey
|
|
170
|
+
@return Observable<TValue?>
|
|
171
|
+
]=]
|
|
172
|
+
function ObservableCountingMap:ObserveAtKey(key)
|
|
173
|
+
assert(key ~= nil, "Bad key")
|
|
174
|
+
|
|
175
|
+
return self._keySubTable:Observe(key, function(sub)
|
|
176
|
+
sub:Fire(self._map[key] or 0)
|
|
177
|
+
end)
|
|
178
|
+
end
|
|
179
|
+
|
|
129
180
|
--[=[
|
|
130
181
|
Observes all keys in the map
|
|
131
182
|
@return Observable<Brio<T>>
|
|
@@ -250,11 +301,13 @@ function ObservableCountingMap:Add(key, amount)
|
|
|
250
301
|
|
|
251
302
|
if self.Destroy then
|
|
252
303
|
self.KeyChanged:Fire(key, 0)
|
|
304
|
+
self._keySubTable:Fire(key, 0)
|
|
253
305
|
end
|
|
254
306
|
else
|
|
255
307
|
-- Update item
|
|
256
308
|
self._map[key] = newValue
|
|
257
309
|
self.KeyChanged:Fire(key, newValue)
|
|
310
|
+
self._keySubTable:Fire(key, newValue)
|
|
258
311
|
end
|
|
259
312
|
else
|
|
260
313
|
-- Add item
|
|
@@ -269,6 +322,7 @@ function ObservableCountingMap:Add(key, amount)
|
|
|
269
322
|
|
|
270
323
|
if self.Destroy then
|
|
271
324
|
self.KeyChanged:Fire(key, amount)
|
|
325
|
+
self._keySubTable:Fire(key, amount)
|
|
272
326
|
end
|
|
273
327
|
end
|
|
274
328
|
|
|
@@ -122,16 +122,15 @@ function ObservableMap:_observeKeyValueChanged(packValue)
|
|
|
122
122
|
handleValue(key, value)
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
maid:GiveTask(self.KeyValueChanged:Connect(handleValue))
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
self._maid[sub] = maid
|
|
128
|
+
maid:GiveTask(function()
|
|
128
129
|
self._maid[sub] = nil
|
|
129
|
-
conn:Disconnect()
|
|
130
130
|
sub:Complete()
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return cleanup
|
|
131
|
+
end)
|
|
132
|
+
|
|
133
|
+
return maid
|
|
135
134
|
end)
|
|
136
135
|
end
|
|
137
136
|
|