@quenty/rx 13.16.0 → 13.16.1

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,14 @@
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
+ ## [13.16.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rx@13.16.0...@quenty/rx@13.16.1) (2025-03-21)
7
+
8
+ **Note:** Version bump only for package @quenty/rx
9
+
10
+
11
+
12
+
13
+
6
14
  # [13.16.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rx@13.15.0...@quenty/rx@13.16.0) (2025-02-18)
7
15
 
8
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/rx",
3
- "version": "13.16.0",
3
+ "version": "13.16.1",
4
4
  "description": "Quenty's reactive library for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,18 +28,18 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@quenty/cancellabledelay": "^3.5.0",
31
- "@quenty/canceltoken": "^11.11.0",
32
- "@quenty/ducktype": "^5.8.0",
31
+ "@quenty/canceltoken": "^11.11.1",
32
+ "@quenty/ducktype": "^5.8.1",
33
33
  "@quenty/loader": "^10.8.0",
34
34
  "@quenty/maid": "^3.4.0",
35
- "@quenty/promise": "^10.10.0",
35
+ "@quenty/promise": "^10.10.1",
36
36
  "@quenty/signal": "^7.10.0",
37
37
  "@quenty/symbol": "^3.4.0",
38
- "@quenty/table": "^3.7.0",
38
+ "@quenty/table": "^3.7.1",
39
39
  "@quenty/throttle": "^10.9.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "184a407d8d7366c39009444c3c9a7023cb176471"
44
+ "gitHead": "6b7c3e15e60cdb185986207b574e2b5591261e7a"
45
45
  }
package/src/Shared/Rx.lua CHANGED
@@ -42,10 +42,8 @@ end
42
42
  local Rx = {
43
43
  EMPTY = Observable.new(function(sub)
44
44
  sub:Complete()
45
- end);
46
- NEVER = Observable.new(function(_)
47
-
48
- end);
45
+ end),
46
+ NEVER = Observable.new(function(_) end),
49
47
  }
50
48
 
51
49
  --[=[
@@ -59,7 +57,13 @@ function Rx.pipe(transformers)
59
57
  assert(type(transformers) == "table", "Bad transformers")
60
58
  for index, transformer in pairs(transformers) do
61
59
  if type(transformer) ~= "function" then
62
- error(string.format("[Rx.pipe] Bad pipe value of type %q at index %q, expected function", type(transformer), tostring(index)))
60
+ error(
61
+ string.format(
62
+ "[Rx.pipe] Bad pipe value of type %q at index %q, expected function",
63
+ type(transformer),
64
+ tostring(index)
65
+ )
66
+ )
63
67
  end
64
68
  end
65
69
 
@@ -71,7 +75,14 @@ function Rx.pipe(transformers)
71
75
  current = transformer(current)
72
76
 
73
77
  if not (type(current) == "table" and current.ClassName == "Observable") then
74
- error(string.format("[Rx.pipe] - Failed to transform %q in pipe, made %q (%s)", tostring(key), tostring(current), tostring(type(current) == "table" and current.ClassName or "")))
78
+ error(
79
+ string.format(
80
+ "[Rx.pipe] - Failed to transform %q in pipe, made %q (%s)",
81
+ tostring(key),
82
+ tostring(current),
83
+ tostring(type(current) == "table" and current.ClassName or "")
84
+ )
85
+ )
75
86
  end
76
87
  end
77
88
 
@@ -95,7 +106,7 @@ function Rx.of(...)
95
106
  local args = table.pack(...)
96
107
 
97
108
  return Observable.new(function(sub)
98
- for i=1, args.n do
109
+ for i = 1, args.n do
99
110
  sub:Fire(args[i])
100
111
  end
101
112
 
@@ -287,27 +298,24 @@ function Rx.tap(onFire, onError, onComplete)
287
298
  assert(Observable.isObservable(source), "Bad observable")
288
299
 
289
300
  return Observable.new(function(sub)
290
- return source:Subscribe(
291
- function(...)
292
- if onFire then
293
- onFire(...)
294
- end
295
- if sub:IsPending() then
296
- sub:Fire(...)
297
- end
298
- end,
299
- function(...)
300
- if onError then
301
- onError(...)
302
- end
303
- sub:Fail(...)
304
- end,
305
- function(...)
306
- if onComplete then
307
- onComplete(...)
308
- end
309
- sub:Complete(...)
310
- end)
301
+ return source:Subscribe(function(...)
302
+ if onFire then
303
+ onFire(...)
304
+ end
305
+ if sub:IsPending() then
306
+ sub:Fire(...)
307
+ end
308
+ end, function(...)
309
+ if onError then
310
+ onError(...)
311
+ end
312
+ sub:Fail(...)
313
+ end, function(...)
314
+ if onComplete then
315
+ onComplete(...)
316
+ end
317
+ sub:Complete(...)
318
+ end)
311
319
  end)
312
320
  end
313
321
  end
@@ -411,11 +419,11 @@ end
411
419
  --[=[
412
420
  Same as [Rx.share] except it also replays the value
413
421
 
414
- @param bufferSize number -- Number of entries to cache
415
- @param windowTimeSeconds number -- Time
422
+ @param bufferSize number? -- Number of entries to cache
423
+ @param windowTimeSeconds number? -- Time
416
424
  @return (source: Observable) -> Observable
417
425
  ]=]
418
- function Rx.shareReplay(bufferSize, windowTimeSeconds)
426
+ function Rx.shareReplay(bufferSize: number?, windowTimeSeconds: number?)
419
427
  assert(type(bufferSize) == "number" or bufferSize == nil, "Bad bufferSize")
420
428
  assert(type(windowTimeSeconds) == "number" or windowTimeSeconds == nil, "Bad windowTimeSeconds")
421
429
 
@@ -550,6 +558,7 @@ end
550
558
  ]=]
551
559
  function Rx.startFrom(callback)
552
560
  assert(type(callback) == "function", "Bad callback")
561
+
553
562
  return function(source)
554
563
  assert(Observable.isObservable(source), "Bad observable")
555
564
 
@@ -639,17 +648,14 @@ function Rx.reduce(reducer, seed)
639
648
  local maid = Maid.new()
640
649
  local current = seed
641
650
 
642
- maid:GiveTask(source:Subscribe(
643
- function(...)
644
- current = reducer(current, ...)
645
- end,
646
- function(...)
647
- sub:Fail(...)
648
- end,
649
- function()
650
- -- On complete emit the result.
651
- sub:Fire(current)
652
- end))
651
+ maid:GiveTask(source:Subscribe(function(...)
652
+ current = reducer(current, ...)
653
+ end, function(...)
654
+ sub:Fail(...)
655
+ end, function()
656
+ -- On complete emit the result.
657
+ sub:Fire(current)
658
+ end))
653
659
 
654
660
  return maid
655
661
  end)
@@ -679,25 +685,22 @@ function Rx.defaultsTo(value)
679
685
 
680
686
  local fired = false
681
687
 
682
- maid:GiveTask(source:Subscribe(
683
- function(...)
688
+ maid:GiveTask(source:Subscribe(function(...)
689
+ fired = true
690
+ sub:Fire(...)
691
+ end, function(...)
692
+ if not fired then
684
693
  fired = true
685
- sub:Fire(...)
686
- end,
687
- function(...)
688
- if not fired then
689
- fired = true
690
- sub:Fire(value)
691
- end
692
- sub:Fail(...)
693
- end,
694
- function(...)
695
- if not fired then
696
- fired = true
697
- sub:Fire(value)
698
- end
699
- sub:Complete(...)
700
- end))
694
+ sub:Fire(value)
695
+ end
696
+ sub:Fail(...)
697
+ end, function(...)
698
+ if not fired then
699
+ fired = true
700
+ sub:Fire(value)
701
+ end
702
+ sub:Complete(...)
703
+ end))
701
704
 
702
705
  if not fired then
703
706
  fired = true
@@ -741,22 +744,19 @@ function Rx.endWith(values)
741
744
  return Observable.new(function(sub)
742
745
  local maid = Maid.new()
743
746
 
744
- maid:GiveTask(source:Subscribe(
745
- function(...)
746
- sub:Fire(...)
747
- end,
748
- function(...)
749
- for _, item in pairs(values) do
750
- sub:Fire(item)
751
- end
752
- sub:Fail(...)
753
- end,
754
- function()
755
- for _, item in pairs(values) do
756
- sub:Fire(item)
757
- end
758
- sub:Complete()
759
- end))
747
+ maid:GiveTask(source:Subscribe(function(...)
748
+ sub:Fire(...)
749
+ end, function(...)
750
+ for _, item in pairs(values) do
751
+ sub:Fire(item)
752
+ end
753
+ sub:Fail(...)
754
+ end, function()
755
+ for _, item in pairs(values) do
756
+ sub:Fire(item)
757
+ end
758
+ sub:Complete()
759
+ end))
760
760
 
761
761
  return maid
762
762
  end)
@@ -785,14 +785,11 @@ function Rx.where(predicate)
785
785
  assert(Observable.isObservable(source), "Bad observable")
786
786
 
787
787
  return Observable.new(function(sub)
788
- return source:Subscribe(
789
- function(...)
790
- if predicate(...) then
791
- sub:Fire(...)
792
- end
793
- end,
794
- sub:GetFailComplete()
795
- )
788
+ return source:Subscribe(function(...)
789
+ if predicate(...) then
790
+ sub:Fire(...)
791
+ end
792
+ end, sub:GetFailComplete())
796
793
  end)
797
794
  end
798
795
  end
@@ -816,18 +813,15 @@ function Rx.distinct()
816
813
  return Observable.new(function(sub)
817
814
  local last = UNSET_VALUE
818
815
 
819
- return source:Subscribe(
820
- function(value)
821
- -- TODO: Support tuples
822
- if last == value then
823
- return
824
- end
816
+ return source:Subscribe(function(value)
817
+ -- TODO: Support tuples
818
+ if last == value then
819
+ return
820
+ end
825
821
 
826
- last = value
827
- sub:Fire(last)
828
- end,
829
- sub:GetFailComplete()
830
- )
822
+ last = value
823
+ sub:Fire(last)
824
+ end, sub:GetFailComplete())
831
825
  end)
832
826
  end
833
827
  end
@@ -1005,14 +999,12 @@ function Rx.flatMap(project)
1005
999
  subscriptions[subscription] = true
1006
1000
  end
1007
1001
 
1008
- local outerSubscription = source:Subscribe(onNextObservable,
1009
- function(...)
1010
- sub:Fail(...)
1011
- end,
1012
- function()
1013
- isComplete = true
1014
- checkComplete()
1015
- end)
1002
+ local outerSubscription = source:Subscribe(onNextObservable, function(...)
1003
+ sub:Fail(...)
1004
+ end, function()
1005
+ isComplete = true
1006
+ checkComplete()
1007
+ end)
1016
1008
 
1017
1009
  return function()
1018
1010
  pendingCount = 0
@@ -1166,15 +1158,13 @@ function Rx.switchMap(project)
1166
1158
  insideSubscription = subscription
1167
1159
  end
1168
1160
 
1169
- local outerSubscription = source:Subscribe(onNextObservable,
1170
- function(...)
1171
- outerIndex = nil
1172
- sub:Fail(...)
1173
- end,
1174
- function()
1175
- isComplete = true
1176
- checkComplete()
1177
- end)
1161
+ local outerSubscription = source:Subscribe(onNextObservable, function(...)
1162
+ outerIndex = nil
1163
+ sub:Fail(...)
1164
+ end, function()
1165
+ isComplete = true
1166
+ checkComplete()
1167
+ end)
1178
1168
 
1179
1169
  return function()
1180
1170
  outerIndex = nil
@@ -1322,23 +1312,19 @@ function Rx.combineLatestAll()
1322
1312
  alive = false
1323
1313
  end)
1324
1314
 
1325
- maid:GiveTask(source:Subscribe(
1326
- function(value)
1327
- assert(Observable.isObservable(value))
1315
+ maid:GiveTask(source:Subscribe(function(value)
1316
+ assert(Observable.isObservable(value))
1328
1317
 
1329
- table.insert(observables, value)
1330
- end,
1331
- function(...)
1332
- sub:Fail(...)
1333
- end,
1334
- function()
1335
- if not alive then
1336
- return
1337
- end
1318
+ table.insert(observables, value)
1319
+ end, function(...)
1320
+ sub:Fail(...)
1321
+ end, function()
1322
+ if not alive then
1323
+ return
1324
+ end
1338
1325
 
1339
- maid:GiveTask(Rx.combineLatest(observables))
1340
- :Subscribe(sub:GetFireFailComplete())
1341
- end))
1326
+ maid:GiveTask(Rx.combineLatest(observables)):Subscribe(sub:GetFireFailComplete())
1327
+ end))
1342
1328
 
1343
1329
  return maid
1344
1330
  end)
@@ -1383,27 +1369,24 @@ function Rx.catchError(callback)
1383
1369
  alive = false
1384
1370
  end)
1385
1371
 
1386
- maid:GiveTask(source:Subscribe(
1387
- function(...)
1388
- sub:Fire(...)
1389
- end,
1390
- function(...)
1391
- if not alive then
1392
- -- if we failed because maid was cancelled, then we'll get called here?
1393
- -- I think.
1394
- return
1395
- end
1372
+ maid:GiveTask(source:Subscribe(function(...)
1373
+ sub:Fire(...)
1374
+ end, function(...)
1375
+ if not alive then
1376
+ -- if we failed because maid was cancelled, then we'll get called here?
1377
+ -- I think.
1378
+ return
1379
+ end
1396
1380
 
1397
- -- at this point, we can only have one error, so we need to subscribe to the result
1398
- -- and continue the observiable
1399
- local observable = callback(...)
1400
- assert(Observable.isObservable(observable), "Bad observable")
1381
+ -- at this point, we can only have one error, so we need to subscribe to the result
1382
+ -- and continue the observiable
1383
+ local observable = callback(...)
1384
+ assert(Observable.isObservable(observable), "Bad observable")
1401
1385
 
1402
- maid:GiveTask(observable:Subscribe(sub:GetFireFailComplete()))
1403
- end,
1404
- function()
1405
- sub:Complete()
1406
- end));
1386
+ maid:GiveTask(observable:Subscribe(sub:GetFireFailComplete()))
1387
+ end, function()
1388
+ sub:Complete()
1389
+ end))
1407
1390
 
1408
1391
  return maid
1409
1392
  end)
@@ -1481,20 +1464,17 @@ function Rx.combineLatest(observables)
1481
1464
  continue
1482
1465
  end
1483
1466
 
1484
- maid:GiveTask(observer:Subscribe(
1485
- function(value)
1486
- if latest[key] == UNSET_VALUE then
1487
- unset -= 1
1488
- end
1467
+ maid:GiveTask(observer:Subscribe(function(value)
1468
+ if latest[key] == UNSET_VALUE then
1469
+ unset -= 1
1470
+ end
1489
1471
 
1490
- latest[key] = value
1472
+ latest[key] = value
1491
1473
 
1492
- if unset == 0 then
1493
- sub:Fire(table.freeze(table.clone(latest)))
1494
- end
1495
- end,
1496
- failOnFirst,
1497
- completeOnAllPendingDone))
1474
+ if unset == 0 then
1475
+ sub:Fire(table.freeze(table.clone(latest)))
1476
+ end
1477
+ end, failOnFirst, completeOnAllPendingDone))
1498
1478
  end
1499
1479
 
1500
1480
  return maid
@@ -1562,30 +1542,26 @@ function Rx.combineLatestDefer(observables)
1562
1542
  continue
1563
1543
  end
1564
1544
 
1565
- maid:GiveTask(observer:Subscribe(
1566
- function(value)
1567
- if latest[key] == UNSET_VALUE then
1568
- unset -= 1
1569
- end
1545
+ maid:GiveTask(observer:Subscribe(function(value)
1546
+ if latest[key] == UNSET_VALUE then
1547
+ unset -= 1
1548
+ end
1570
1549
 
1571
- latest[key] = value
1550
+ latest[key] = value
1572
1551
 
1573
- if unset == 0 and not queueThread then
1574
- queueThread = task.defer(function()
1575
- queueThread = nil
1576
- sub:Fire(table.freeze(table.clone(latest)))
1577
- end)
1578
- end
1579
- end,
1580
- failOnFirst,
1581
- completeOnAllPendingDone))
1552
+ if unset == 0 and not queueThread then
1553
+ queueThread = task.defer(function()
1554
+ queueThread = nil
1555
+ sub:Fire(table.freeze(table.clone(latest)))
1556
+ end)
1557
+ end
1558
+ end, failOnFirst, completeOnAllPendingDone))
1582
1559
  end
1583
1560
 
1584
1561
  return maid
1585
1562
  end)
1586
1563
  end
1587
1564
 
1588
-
1589
1565
  --[=[
1590
1566
  http://reactivex.io/documentation/operators/using.html
1591
1567
 
@@ -1638,7 +1614,7 @@ end
1638
1614
  @param number number
1639
1615
  @return (source: Observable<T>) -> Observable<T>
1640
1616
  ]=]
1641
- function Rx.take(number)
1617
+ function Rx.take(number: number)
1642
1618
  assert(type(number) == "number", "Bad number")
1643
1619
  assert(number > 0, "Bad number")
1644
1620
 
@@ -1678,7 +1654,7 @@ end
1678
1654
  @param toSkip number
1679
1655
  @return (source: Observable<T>) -> Observable<T>
1680
1656
  ]=]
1681
- function Rx.skip(toSkip)
1657
+ function Rx.skip(toSkip: number)
1682
1658
  assert(type(toSkip) == "number", "Bad toSkip")
1683
1659
  assert(toSkip > 0, "Bad toSkip")
1684
1660
 
@@ -1740,7 +1716,7 @@ end
1740
1716
  @param seconds number
1741
1717
  @return (source: Observable<T>) -> Observable<T>
1742
1718
  ]=]
1743
- function Rx.delay(seconds)
1719
+ function Rx.delay(seconds: number)
1744
1720
  assert(type(seconds) == "number", "Bad seconds")
1745
1721
 
1746
1722
  return function(source)
@@ -1769,7 +1745,7 @@ end
1769
1745
  @param seconds number
1770
1746
  @return Observable<()>
1771
1747
  ]=]
1772
- function Rx.delayed(seconds)
1748
+ function Rx.delayed(seconds: number)
1773
1749
  assert(type(seconds) == "number", "Bad seconds")
1774
1750
 
1775
1751
  return Observable.new(function(sub)
@@ -1786,7 +1762,7 @@ end
1786
1762
  @param seconds number
1787
1763
  @return (source: Observable<number>) -> Observable<number>
1788
1764
  ]=]
1789
- function Rx.timer(initialDelaySeconds, seconds)
1765
+ function Rx.timer(initialDelaySeconds: number, seconds: number)
1790
1766
  assert(type(initialDelaySeconds) == "number" or initialDelaySeconds == nil, "Bad initialDelaySeconds")
1791
1767
  assert(type(seconds) == "number", "Bad seconds")
1792
1768
 
@@ -1817,7 +1793,7 @@ end
1817
1793
  @param seconds number
1818
1794
  @return (source: Observable<number>) -> Observable<number>
1819
1795
  ]=]
1820
- function Rx.interval(seconds)
1796
+ function Rx.interval(seconds: number)
1821
1797
  assert(type(seconds) == "number", "Bad seconds")
1822
1798
 
1823
1799
  return Rx.timer(0, seconds)
@@ -1862,7 +1838,7 @@ function Rx.withLatestFrom(inputObservables)
1862
1838
  end
1863
1839
  end
1864
1840
 
1865
- sub:Fire({value, unpack(latest)})
1841
+ sub:Fire({ value, unpack(latest) })
1866
1842
  end, sub:GetFailComplete()))
1867
1843
 
1868
1844
  return maid
@@ -1883,7 +1859,7 @@ end
1883
1859
  @param throttleConfig { leading = true; trailing = true; }
1884
1860
  @return (source: Observable) -> Observable
1885
1861
  ]=]
1886
- function Rx.throttleTime(duration, throttleConfig)
1862
+ function Rx.throttleTime(duration: number, throttleConfig)
1887
1863
  assert(type(duration) == "number", "Bad duration")
1888
1864
  assert(type(throttleConfig) == "table" or throttleConfig == nil, "Bad throttleConfig")
1889
1865
 
@@ -1926,7 +1902,7 @@ function Rx.onlyAfterDefer()
1926
1902
  end
1927
1903
  end, sub:GetFailComplete())
1928
1904
  end)
1929
- end;
1905
+ end
1930
1906
  end
1931
1907
 
1932
1908
  --[=[
@@ -2140,7 +2116,7 @@ function Rx.switchScan(accumulator, seed)
2140
2116
 
2141
2117
  return Rx.pipe({
2142
2118
  Rx.scan(accumulator, seed),
2143
- Rx.switchAll()
2119
+ Rx.switchAll(),
2144
2120
  })
2145
2121
  end
2146
2122
 
@@ -2159,7 +2135,7 @@ function Rx.mergeScan(accumulator, seed)
2159
2135
 
2160
2136
  return Rx.pipe({
2161
2137
  Rx.scan(accumulator, seed),
2162
- Rx.mergeAll();
2138
+ Rx.mergeAll(),
2163
2139
  })
2164
2140
  end
2165
2141