sgr-ksmt / FireSnapshot

A useful Firebase-Cloud-Firestore Wrapper with Codable.
MIT License
56 stars 9 forks source link

Codable extensions #44

Open kevinrenskers opened 4 years ago

kevinrenskers commented 4 years ago

Would be awesome to have extensions that return Codable publishers for the query/document observers.

sgr-ksmt commented 4 years ago

@kevinrenskers Could you give me an example of code that you are expecting?

kevinrenskers commented 4 years ago

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.

sgr-ksmt commented 4 years ago

Nice idea! I will implement extensions for Publisher. But, It takes a while to implement because I'm busy 🙏

kevinrenskers commented 4 years ago

I might send a PR this week. We'll see if I have time :)

kshivang commented 4 years ago

On similar line CombineFirebase is made. It has publisher method for every firebase api. Its source might help.