@quenty/rxbinderutils 9.2.0 → 9.3.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,17 @@
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
+ # [9.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rxbinderutils@9.2.0...@quenty/rxbinderutils@9.3.0) (2023-12-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * RxBinderUtils.observeAllArrayBrio ([#408](https://github.com/Quenty/NevermoreEngine/issues/408)) ([98da8c2](https://github.com/Quenty/NevermoreEngine/commit/98da8c29f61965ebf8ad516a650ccabab7ce6bdb))
12
+
13
+
14
+
15
+
16
+
6
17
  # [9.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rxbinderutils@9.1.1...@quenty/rxbinderutils@9.2.0) (2023-12-14)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/rxbinderutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/rxbinderutils",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "description": "Reactive extensions for binders",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "2c2dbbc0cb2fbb46b4f3270c559c63890fe18b26"
40
+ "gitHead": "d98c14a2c2c27cc066f3b188562a509e4b717d1c"
41
41
  }
@@ -229,4 +229,52 @@ function RxBinderUtils.observeAllBrio(binder)
229
229
  end)
230
230
  end
231
231
 
232
+ --[=[
233
+ Observes all instances bound to the given binder as an unordered array.
234
+
235
+ @param binder Binder
236
+ @return Observable<Brio<{ T }>>
237
+ ]=]
238
+ function RxBinderUtils.observeAllArrayBrio(binder)
239
+ assert(Binder.isBinder(binder), "Bad binder")
240
+
241
+ return Observable.new(function(sub)
242
+ local maid = Maid.new()
243
+
244
+ local array = binder:GetAll()
245
+
246
+ local function emit()
247
+ maid._brio = Brio.new(array)
248
+ sub:Fire(maid._brio)
249
+ end
250
+
251
+ maid:GiveTask(binder:GetClassAddedSignal():Connect(function(class)
252
+ table.insert(array, class)
253
+ emit()
254
+ end))
255
+ maid:GiveTask(binder:GetClassRemovingSignal():Connect(function(class)
256
+ local idx: number? = table.find(array, class)
257
+ if not idx then
258
+ return
259
+ end
260
+ -- Avoid 'table.remove'; that would suck with a very large list.
261
+ -- We're assuming order doesn't matter. Instead, move the back element of the array over.
262
+ -- From earlier benchmarking, calling #arr each time is faster than caching.
263
+ if idx == #array then
264
+ -- Just truncate. Handles case where array is 1 item.
265
+ array[idx] = nil
266
+ else
267
+ -- Move back element forward.
268
+ array[idx] = array[#array]
269
+ array[#array] = nil
270
+ end
271
+ emit()
272
+ end))
273
+
274
+ emit()
275
+
276
+ return maid
277
+ end)
278
+ end
279
+
232
280
  return RxBinderUtils