-- Fires off everytime the link is reconfigured into a valid link
-- Fires with link, linkValue

function RxLinkUtils.observeValidityBrio(linkName, link)
	assert(typeof(link) == "Instance" and link:IsA("ObjectValue"), "Bad link")
	assert(type(linkName) == "string", "Bad linkName")

	return Observable.new(function(sub)
		local maid = Maid.new()

		local function updateValidity()
			if not ((link.Name == linkName) and link.Value) then
				maid._lastValid = nil
				return
			end

			local newValid = Brio.new(link, link.Value)
			maid._lastValid = newValid
			sub:Fire(newValid)
		end

		maid:GiveTask(link:GetPropertyChangedSignal("Value")
			:Connect(updateValidity))
		maid:GiveTask(link:GetPropertyChangedSignal("Name")
			:Connect(updateValidity))
		updateValidity()

		return maid
	end)
end


return RxLinkUtils
