FireSnapshot icon indicating copy to clipboard operation
FireSnapshot copied to clipboard

Codable extensions

Open kevinrenskers opened this issue 5 years ago • 5 comments

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

kevinrenskers avatar Jan 16 '20 10:01 kevinrenskers

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

sgr-ksmt avatar Jan 17 '20 03:01 sgr-ksmt

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.

kevinrenskers avatar Jan 17 '20 20:01 kevinrenskers

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

sgr-ksmt avatar Jan 19 '20 11:01 sgr-ksmt

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

kevinrenskers avatar Jan 19 '20 11:01 kevinrenskers

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

kshivang avatar Mar 30 '20 23:03 kshivang