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

Codable extensions #44

Open
kevinrenskers opened this issue Jan 16, 2020 · 5 comments
Open

Codable extensions #44

kevinrenskers opened this issue Jan 16, 2020 · 5 comments
Labels
FR New feature or request

Comments

@kevinrenskers
Copy link

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

@sgr-ksmt
Copy link
Owner

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

@kevinrenskers
Copy link
Author

kevinrenskers commented Jan 17, 2020

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 sgr-ksmt added the FR New feature or request label Jan 19, 2020
@sgr-ksmt
Copy link
Owner

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

@kevinrenskers
Copy link
Author

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

@kshivang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FR New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants