@quenty/observablecollection 12.4.0 → 12.5.1-canary.496.cb49bdf.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,25 @@
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.5.1-canary.496.cb49bdf.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.5.0...@quenty/observablecollection@12.5.1-canary.496.cb49bdf.0) (2024-09-20)
7
+
8
+ **Note:** Version bump only for package @quenty/observablecollection
9
+
10
+
11
+
12
+
13
+
14
+ # [12.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.4.0...@quenty/observablecollection@12.5.0) (2024-09-12)
15
+
16
+
17
+ ### Features
18
+
19
+ * Add ObservableCountingMap:ObservePairsBrio() and ObservableCountingMap:ObserveAtKey(key) ([b3baa09](https://github.com/Quenty/NevermoreEngine/commit/b3baa09563be96ccfd985496e833ad87a78bc953))
20
+
21
+
22
+
23
+
24
+
6
25
  # [12.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.3.1...@quenty/observablecollection@12.4.0) (2024-08-09)
7
26
 
8
27
  **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.4.0",
3
+ "version": "12.5.1-canary.496.cb49bdf.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.3.0",
31
- "@quenty/brio": "^14.4.0",
32
- "@quenty/ducktype": "^5.3.0",
33
- "@quenty/loader": "^10.3.0",
34
- "@quenty/maid": "^3.2.0",
35
- "@quenty/promise": "^10.3.0",
36
- "@quenty/rx": "^13.4.0",
37
- "@quenty/signal": "^7.3.0",
38
- "@quenty/steputils": "^3.4.0",
39
- "@quenty/symbol": "^3.1.0",
40
- "@quenty/valueobject": "^13.4.0"
30
+ "@quenty/baseobject": "10.4.0",
31
+ "@quenty/brio": "14.5.0",
32
+ "@quenty/ducktype": "5.4.0",
33
+ "@quenty/loader": "10.4.0",
34
+ "@quenty/maid": "3.3.0",
35
+ "@quenty/promise": "10.4.0",
36
+ "@quenty/rx": "13.5.0",
37
+ "@quenty/signal": "7.4.0",
38
+ "@quenty/steputils": "3.4.0",
39
+ "@quenty/symbol": "3.1.0",
40
+ "@quenty/valueobject": "13.5.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@quenty/blend": "^12.4.0"
43
+ "@quenty/blend": "12.5.1-canary.496.cb49bdf.0"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "ba466bdbc05c42fb607cf5e228c16339201d21d7"
48
+ "gitHead": "cb49bdf8d79aac6e6901901c914271148df358b2"
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
- return Observable.new(function(sub)
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