Open kevinrenskers opened 4 years ago
@kevinrenskers Could you give me an example of code that you are expecting?
In your documentation you have these two examples:
// Listen document
let listener = Snapshot.listen(.product("some_product_id")) { result in
switch result {
case let .success(product):
print("listened new product", product.name)
case let .failure(error):
print(error)
}
}
// Listen documents
let listener = Snapshot.listen(.products) { result in
switch result {
case let .success(products):
print("listened new products", products.count)
case let .failure(error):
print(error)
}
}
It would be great if these would not take a completion handler but instead returned a Publisher. So for example
Snapshot.listen(.product("some_product_id"))
.sink(receiveCompletion: { completion in
print(completion)
}, receiveValue: { products in
print("listened new products", products.count)
})
.store(in: &cancellables)
By returning a publisher, we can combine them with other publishers, assign the result to a writable keypath, map and filter, and all the other things we can do with streams.
Nice idea! I will implement extensions for Publisher. But, It takes a while to implement because I'm busy 🙏
I might send a PR this week. We'll see if I have time :)
On similar line CombineFirebase is made. It has publisher method for every firebase api. Its source might help.
Would be awesome to have extensions that return Codable publishers for the query/document observers.