Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservableList.fromObservableBrio and ObservableSet.fromObservableBrio. #509

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/observablecollection/src/Shared/ObservableList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ function ObservableList.new()
return self
end

--[=[
Constructs an ObservableList populated via an observable of Brios
@param observable Observable<Brio<T>>
@return ObservableList<T>
]=]
function ObservableList.fromObservableBrio(observable)
local list = ObservableList.new()

list._maid:GiveTask(observable:Subscribe(function(value)
assert(Brio.isBrio(value), "Observable must emit brio")

if value:IsDead() then
return
end

value:ToMaid():GiveTask(list:Add(value:GetValue()))
end))

return list
end

--[=[
Returns whether the value is an observable list
@param value any
Expand Down
21 changes: 21 additions & 0 deletions src/observablecollection/src/Shared/ObservableSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ function ObservableSet.new()
return self
end

--[=[
Constructs an ObservableSet populated via an observable of Brios
@param observable Observable<Brio<T>>
@return ObservableSet<T>
]=]
function ObservableSet.fromObservableBrio(observable)
local set = ObservableSet.new()

set._maid:GiveTask(observable:Subscribe(function(value)
assert(Brio.isBrio(value), "Observable must emit brio")

if value:IsDead() then
return
end

value:ToMaid():GiveTask(set:Add(value:GetValue()))
end))

return set
end

--[=[
Returns whether the value is an observable set
@param value any
Expand Down
Loading