@quenty/observablecollection 3.0.0 → 3.1.1-canary.270.0fe7bd3.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,28 @@
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
+ ## [3.1.1-canary.270.0fe7bd3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@3.1.0...@quenty/observablecollection@3.1.1-canary.270.0fe7bd3.0) (2022-07-02)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add ObservableMapSet:GetSetCount() and ObservableMapSet:ObserveSetCount() ([6a25f61](https://github.com/Quenty/NevermoreEngine/commit/6a25f61d8dcadd9dda56daf1a52c4b4186740efe))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@3.0.0...@quenty/observablecollection@3.1.0) (2022-06-21)
18
+
19
+
20
+ ### Features
21
+
22
+ * Add more API surface to ObservableMapSet ([f2ae08b](https://github.com/Quenty/NevermoreEngine/commit/f2ae08ba714e3aefc9f9bf1ae30fefc679535d2b))
23
+
24
+
25
+
26
+
27
+
6
28
  # [3.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@2.2.0...@quenty/observablecollection@3.0.0) (2022-05-21)
7
29
 
8
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/observablecollection",
3
- "version": "3.0.0",
3
+ "version": "3.1.1-canary.270.0fe7bd3.0",
4
4
  "description": "An observable set",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,17 +27,17 @@
27
27
  "Quenty"
28
28
  ],
29
29
  "dependencies": {
30
- "@quenty/brio": "^6.0.0",
31
- "@quenty/loader": "^5.0.0",
32
- "@quenty/maid": "^2.3.0",
33
- "@quenty/promise": "^5.0.0",
34
- "@quenty/rx": "^5.0.0",
35
- "@quenty/signal": "^2.2.0",
36
- "@quenty/symbol": "^2.1.0",
37
- "@quenty/valuebaseutils": "^5.0.0"
30
+ "@quenty/brio": "6.1.0",
31
+ "@quenty/loader": "5.0.0",
32
+ "@quenty/maid": "2.3.0",
33
+ "@quenty/promise": "5.0.0",
34
+ "@quenty/rx": "5.1.0",
35
+ "@quenty/signal": "2.2.0",
36
+ "@quenty/symbol": "2.1.0",
37
+ "@quenty/valuebaseutils": "5.1.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "9f7eaea7543c33c89d2e32c38491b13f9271f4f7"
42
+ "gitHead": "0fe7bd3216177265038ff7d3f83d1d47e748141c"
43
43
  }
@@ -165,6 +165,21 @@ function ObservableList:ObserveIndexByKey(key)
165
165
  end)
166
166
  end
167
167
 
168
+ --[=[
169
+ Gets the current index from the key
170
+
171
+ @param key Symbol
172
+ @return number
173
+ ]=]
174
+ function ObservableList:GetIndexByKey(key)
175
+ local currentIndex = self._indexes[key]
176
+ if currentIndex then
177
+ return currentIndex
178
+ else
179
+ return nil
180
+ end
181
+ end
182
+
168
183
  --[=[
169
184
  Gets the count of items in the list
170
185
  @return number
@@ -11,6 +11,9 @@ local Maid = require("Maid")
11
11
  local Observable = require("Observable")
12
12
  local ObservableSet = require("ObservableSet")
13
13
  local Signal = require("Signal")
14
+ local Brio = require("Brio")
15
+ local RxBrioUtils = require("RxBrioUtils")
16
+ local RxValueBaseUtils = require("RxValueBaseUtils")
14
17
 
15
18
  local ObservableMapSet = {}
16
19
  ObservableMapSet.ClassName = "ObservableMapSet"
@@ -44,6 +47,10 @@ function ObservableMapSet.new()
44
47
  self.SetRemoved = Signal.new() -- :Fire(key)
45
48
  self._maid:GiveTask(self.SetRemoved)
46
49
 
50
+ self._setCount = Instance.new("IntValue")
51
+ self._setCount.Value = 0
52
+ self._maid:GiveTask(self._setCount)
53
+
47
54
  return self
48
55
  end
49
56
 
@@ -52,7 +59,7 @@ end
52
59
  that need to be looked up by key.
53
60
 
54
61
  @param entry TValue
55
- @param observeKey Observable<Brio<TKey>>
62
+ @param observeKey Observable<TKey>
56
63
  ]=]
57
64
  function ObservableMapSet:Add(entry, observeKey)
58
65
  local maid = Maid.new()
@@ -87,6 +94,27 @@ function ObservableMapSet:Add(entry, observeKey)
87
94
  return maid
88
95
  end
89
96
 
97
+ --[=[
98
+ Gets how many sets exist
99
+ @return number
100
+ ]=]
101
+ function ObservableMapSet:GetSetCount()
102
+ return self._setCount.Value
103
+ end
104
+
105
+ --[=[
106
+ Observes how many sets exist
107
+ @return Observable<number>
108
+ ]=]
109
+ function ObservableMapSet:ObserveSetCount()
110
+ return RxValueBaseUtils.observeValue(self._setCount)
111
+ end
112
+
113
+ --[=[
114
+ Observes all items for the given key
115
+ @param key TKey
116
+ @return Observable<Brio<TValue>>
117
+ ]=]
90
118
  function ObservableMapSet:ObserveItemsForKeyBrio(key)
91
119
  assert(key ~= nil, "Bad key")
92
120
 
@@ -124,7 +152,14 @@ function ObservableMapSet:ObserveItemsForKeyBrio(key)
124
152
  end)
125
153
  end
126
154
 
155
+ --[=[
156
+ Gets a list for a given key
157
+ @param key TKey
158
+ @return { TValue }
159
+ ]=]
127
160
  function ObservableMapSet:GetListForKey(key)
161
+ assert(key ~= nil, "Bad key")
162
+
128
163
  local observableSet = self._observableSetMap[key]
129
164
  if not observableSet then
130
165
  return {}
@@ -133,10 +168,64 @@ function ObservableMapSet:GetListForKey(key)
133
168
  return observableSet:GetList()
134
169
  end
135
170
 
171
+ --[=[
172
+ Gets the observable set for the given key
173
+ @param key TKey
174
+ @return ObservableSet<TValue>
175
+ ]=]
136
176
  function ObservableMapSet:GetObservableSetForKey(key)
177
+ assert(key ~= nil, "Bad key")
178
+
137
179
  return self._observableSetMap[key]
138
180
  end
139
181
 
182
+ function ObservableMapSet:ObserveSetBrio(key)
183
+ assert(key ~= nil, "Bad key")
184
+
185
+ return Observable.new(function(sub)
186
+ local topMaid = Maid.new()
187
+
188
+ local function connect()
189
+ local brio
190
+
191
+ local set = self._observableSetMap[key]
192
+ if set then
193
+ brio = Brio.new(set)
194
+ sub:Fire(brio)
195
+ end
196
+
197
+ topMaid._current = brio
198
+ end
199
+
200
+ topMaid:GiveTask(self.SetAdded:Connect(function(addedKey)
201
+ if addedKey == key then
202
+ connect()
203
+ end
204
+ end))
205
+
206
+ topMaid:GiveTask(self.SetRemoved:Connect(function(removedKey)
207
+ if removedKey == key then
208
+ connect()
209
+ end
210
+ end))
211
+
212
+ connect()
213
+
214
+ return topMaid
215
+ end)
216
+ end
217
+
218
+ function ObservableMapSet:ObserveCountForKey(key)
219
+ assert(key ~= nil, "Bad key")
220
+
221
+ return self:ObserveSetBrio(key):Pipe({
222
+ RxBrioUtils.switchMapBrio(function(observableSet)
223
+ return observableSet:ObserveCount()
224
+ end);
225
+ RxBrioUtils.emitOnDeath(0);
226
+ })
227
+ end
228
+
140
229
  function ObservableMapSet:_addToObservableSet(key, entry)
141
230
  local set = self:_getOrCreateObservableSet(key)
142
231
  set:Add(entry)
@@ -172,6 +261,8 @@ function ObservableMapSet:_removeObservableSet(key)
172
261
  if self.SetRemoved.Destroy then
173
262
  self.SetRemoved:Fire(key)
174
263
  end
264
+
265
+ self._setCount.Value = self._setCount.Value - 1
175
266
  end
176
267
  end
177
268
 
@@ -187,6 +278,7 @@ function ObservableMapSet:_getOrCreateObservableSet(key)
187
278
  self._observableSetMap[key] = set
188
279
 
189
280
  self.SetAdded:Fire(key, set)
281
+ self._setCount.Value = self._setCount.Value + 1
190
282
 
191
283
  self._maid[set] = maid
192
284
  return set