@quenty/rx 3.1.2 → 3.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 +22 -0
- package/package.json +4 -4
- package/src/Shared/Rx.lua +52 -36
- package/src/Shared/Rx.spec.lua +49 -0
- package/src/node_modules.project.json +1 -1
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.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rx@3.2.0...@quenty/rx@3.3.0) (2021-11-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Support MacOS syncing ([#225](https://github.com/Quenty/NevermoreEngine/issues/225)) ([03f9183](https://github.com/Quenty/NevermoreEngine/commit/03f918392c6a5bdd33f8a17c38de371d1e06c67a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rx@3.1.2...@quenty/rx@3.2.0) (2021-10-30)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* combineLatest may also combine none-observables which are treated as raw values (for now). ([9daebde](https://github.com/Quenty/NevermoreEngine/commit/9daebde70584cee5c0e71d1faa92b2d6249cf644))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [3.1.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/rx@3.1.1...@quenty/rx@3.1.2) (2021-10-30)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @quenty/rx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/rx",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Quenty's reactive library for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@quenty/loader": "^3.1.1",
|
|
31
31
|
"@quenty/maid": "^2.0.1",
|
|
32
|
-
"@quenty/promise": "^3.
|
|
32
|
+
"@quenty/promise": "^3.2.0",
|
|
33
33
|
"@quenty/signal": "^2.0.0",
|
|
34
34
|
"@quenty/symbol": "^2.0.0",
|
|
35
35
|
"@quenty/table": "^2.1.0",
|
|
36
|
-
"@quenty/throttle": "^3.
|
|
36
|
+
"@quenty/throttle": "^3.2.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "87ab1435a59a05e7dd745db1dfcec26116d1d71d"
|
|
42
42
|
}
|
package/src/Shared/Rx.lua
CHANGED
|
@@ -96,13 +96,10 @@ end
|
|
|
96
96
|
-- https://rxjs-dev.firebaseapp.com/api/index/function/fromEvent
|
|
97
97
|
function Rx.fromSignal(event)
|
|
98
98
|
return Observable.new(function(sub)
|
|
99
|
-
local maid = Maid.new()
|
|
100
99
|
-- This stream never completes or fails!
|
|
101
|
-
|
|
100
|
+
return event:Connect(function(...)
|
|
102
101
|
sub:Fire(...)
|
|
103
|
-
end)
|
|
104
|
-
|
|
105
|
-
return maid
|
|
102
|
+
end)
|
|
106
103
|
end)
|
|
107
104
|
end
|
|
108
105
|
|
|
@@ -593,8 +590,8 @@ function Rx.finalize(finalizerCallback)
|
|
|
593
590
|
end
|
|
594
591
|
end
|
|
595
592
|
|
|
596
|
-
-- https://rxjs.dev/api/operators/
|
|
597
|
-
function Rx.
|
|
593
|
+
-- https://rxjs.dev/api/operators/combineLatestAll
|
|
594
|
+
function Rx.combineLatestAll()
|
|
598
595
|
return function(source)
|
|
599
596
|
return Observable.new(function(sub)
|
|
600
597
|
local observables = {}
|
|
@@ -628,6 +625,9 @@ function Rx.combineAll()
|
|
|
628
625
|
end
|
|
629
626
|
end
|
|
630
627
|
|
|
628
|
+
-- This is for backwards compatability, and is deprecated
|
|
629
|
+
Rx.combineAll = Rx.combineLatestAll
|
|
630
|
+
|
|
631
631
|
-- NOTE: Untested
|
|
632
632
|
function Rx.catchError(callback)
|
|
633
633
|
assert(type(callback) == "function", "Bad callback")
|
|
@@ -672,24 +672,26 @@ end
|
|
|
672
672
|
function Rx.combineLatest(observables)
|
|
673
673
|
assert(type(observables) == "table", "Bad observables")
|
|
674
674
|
|
|
675
|
-
for _, observable in pairs(observables) do
|
|
676
|
-
assert(Observable.isObservable(observable), "Not an observable")
|
|
677
|
-
end
|
|
678
|
-
|
|
679
675
|
return Observable.new(function(sub)
|
|
680
|
-
|
|
676
|
+
local pending = 0
|
|
677
|
+
|
|
678
|
+
local latest = {}
|
|
679
|
+
for key, value in pairs(observables) do
|
|
680
|
+
if Observable.isObservable(value) then
|
|
681
|
+
pending = pending + 1
|
|
682
|
+
latest[key] = UNSET_VALUE
|
|
683
|
+
else
|
|
684
|
+
latest[key] = value
|
|
685
|
+
end
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
if pending == 0 then
|
|
689
|
+
sub:Fire(latest)
|
|
681
690
|
sub:Complete()
|
|
682
691
|
return
|
|
683
692
|
end
|
|
684
693
|
|
|
685
694
|
local maid = Maid.new()
|
|
686
|
-
local pending = 0
|
|
687
|
-
|
|
688
|
-
local latest = {}
|
|
689
|
-
for key, _ in pairs(observables) do
|
|
690
|
-
pending = pending + 1
|
|
691
|
-
latest[key] = UNSET_VALUE
|
|
692
|
-
end
|
|
693
695
|
|
|
694
696
|
local function fireIfAllSet()
|
|
695
697
|
for _, value in pairs(latest) do
|
|
@@ -702,21 +704,23 @@ function Rx.combineLatest(observables)
|
|
|
702
704
|
end
|
|
703
705
|
|
|
704
706
|
for key, observer in pairs(observables) do
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
707
|
+
if Observable.isObservable(observer) then
|
|
708
|
+
maid:GiveTask(observer:Subscribe(
|
|
709
|
+
function(value)
|
|
710
|
+
latest[key] = value
|
|
711
|
+
fireIfAllSet()
|
|
712
|
+
end,
|
|
713
|
+
function(...)
|
|
714
|
+
pending = pending - 1
|
|
715
|
+
sub:Fail(...)
|
|
716
|
+
end,
|
|
717
|
+
function()
|
|
718
|
+
pending = pending - 1
|
|
719
|
+
if pending == 0 then
|
|
720
|
+
sub:Complete()
|
|
721
|
+
end
|
|
722
|
+
end))
|
|
723
|
+
end
|
|
720
724
|
end
|
|
721
725
|
|
|
722
726
|
return maid
|
|
@@ -779,8 +783,20 @@ end
|
|
|
779
783
|
-- https://netbasal.com/getting-to-know-the-defer-observable-in-rxjs-a16f092d8c09
|
|
780
784
|
function Rx.defer(observableFactory)
|
|
781
785
|
return Observable.new(function(sub)
|
|
782
|
-
local observable
|
|
783
|
-
|
|
786
|
+
local observable
|
|
787
|
+
local ok, err = pcall(function()
|
|
788
|
+
observable = observableFactory()
|
|
789
|
+
end)
|
|
790
|
+
|
|
791
|
+
if not ok then
|
|
792
|
+
sub:Fail(err)
|
|
793
|
+
return
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
if not Observable.isObservable(observable) then
|
|
797
|
+
sub:Fail("Not an observable")
|
|
798
|
+
return
|
|
799
|
+
end
|
|
784
800
|
|
|
785
801
|
return observable:Subscribe(sub:GetFireFailComplete())
|
|
786
802
|
end)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
-- @module Rx.spec.lua
|
|
3
|
+
|
|
4
|
+
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).load(script)
|
|
5
|
+
|
|
6
|
+
local Rx = require("Rx")
|
|
7
|
+
|
|
8
|
+
return function()
|
|
9
|
+
describe("Rx.combineLatest({})", function()
|
|
10
|
+
local observe = Rx.combineLatest({})
|
|
11
|
+
local externalResult
|
|
12
|
+
|
|
13
|
+
it("should execute immediately", function()
|
|
14
|
+
observe:Subscribe(function(result)
|
|
15
|
+
externalResult = result
|
|
16
|
+
end)
|
|
17
|
+
|
|
18
|
+
expect(externalResult).to.be.a("table")
|
|
19
|
+
end)
|
|
20
|
+
end)
|
|
21
|
+
|
|
22
|
+
describe("Rx.combineLatest({ value = 5 })", function()
|
|
23
|
+
local observe = Rx.combineLatest({ value = 5 })
|
|
24
|
+
local externalResult
|
|
25
|
+
|
|
26
|
+
it("should execute immediately", function()
|
|
27
|
+
observe:Subscribe(function(result)
|
|
28
|
+
externalResult = result
|
|
29
|
+
end)
|
|
30
|
+
|
|
31
|
+
expect(externalResult).to.be.a("table")
|
|
32
|
+
expect(externalResult.value).to.equal(5)
|
|
33
|
+
end)
|
|
34
|
+
end)
|
|
35
|
+
|
|
36
|
+
describe("Rx.combineLatest({ value = Rx.of(5) })", function()
|
|
37
|
+
local observe = Rx.combineLatest({ value = Rx.of(5) })
|
|
38
|
+
local externalResult
|
|
39
|
+
|
|
40
|
+
it("should execute immediately", function()
|
|
41
|
+
observe:Subscribe(function(result)
|
|
42
|
+
externalResult = result
|
|
43
|
+
end)
|
|
44
|
+
|
|
45
|
+
expect(externalResult).to.be.a("table")
|
|
46
|
+
expect(externalResult.value).to.equal(5)
|
|
47
|
+
end)
|
|
48
|
+
end)
|
|
49
|
+
end
|