/
RxBinderGroupUtils.lua
53 lines (41 loc) · 1.18 KB
/
RxBinderGroupUtils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--[=[
Rx utility methods involving [BinderGroup] API surface
@class RxBinderGroupUtils
]=]
local require = require(script.Parent.loader).load(script)
local RxBinderUtils = require("RxBinderUtils")
local Observable = require("Observable")
local Maid = require("Maid")
local Rx = require("Rx")
local RxBinderGroupUtils = {}
--[=[
Observes all binders in a binder group
@param binderGroup BinderGroup<T>
@return Observable<Binder<T>>
]=]
function RxBinderGroupUtils.observeBinders(binderGroup)
assert(type(binderGroup) == "table", "Bad binderGroup")
return Observable.new(function(sub)
local maid = Maid.new()
maid:GiveTask(binderGroup.BinderAdded:Connect(function(binder)
sub:Fire(binder)
end))
for _, binder in pairs(binderGroup:GetBinders()) do
sub:Fire(binder)
end
return maid
end)
end
--[=[
Observes all classes in a given binder group.
@param binderGroup BinderGroup<T>
@return Observable<Brio<T>>
]=]
function RxBinderGroupUtils.observeAllClassesBrio(binderGroup)
assert(type(binderGroup) == "table", "Bad binderGroup")
return RxBinderGroupUtils.observeBinders(binderGroup)
:Pipe({
Rx.flatMap(RxBinderUtils.observeAllBrio)
})
end
return RxBinderGroupUtils