Skip to content

feat: Add Combine support #667

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

Merged
merged 4 commits into from
Aug 12, 2020
Merged

feat: Add Combine support #667

merged 4 commits into from
Aug 12, 2020

Conversation

palpatim
Copy link
Member

@palpatim palpatim commented Jul 23, 2020

This PR adds Combine support to Amplify asynchronous APIs that return results. See README-combine-support.md for details.

Changes:

  • feat: Add Combine support for Amplify operations
  • feat: The AmplifyError protocol now requires conforming types to supply an initializer that takes a description, recovery suggestion, and underlying error. Most existing AmplifyError types will map this to an unknown case
  • feat: GraphQLOperation is now a concrete subclass of AmplifyOperation instead of a typealias
  • feat: GraphQLSubscriptionOperation is now a concrete subclass of AmplifyInProcessReportingOperation instead of a typealias
  • feat: Added public Success and Failure typealiases to AmplifyOperation, to make generics easier to work with
  • feat: Added public InProcess typealias to AmplifyInProcessReportingOperation, to make generics easier to work with
  • feat: HubChannel now conforms to Hashable
  • feat: Added AtomicValue.with method to allow for manipulations of a value inside a block
  • chore: Refactored AWSAPICategoryPlugin to make a dependencies easier to inject at configuration
  • chore: Added unit tests for API subscription use cases

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@drochetti drochetti added this to the 1.1.0 milestone Jul 31, 2020
@palpatim palpatim force-pushed the palpatim/combine-support-take-2 branch from 1c2f420 to 4925f68 Compare August 4, 2020 16:40
@palpatim palpatim changed the title Palpatim/combine support take 2 feat: Add Combine support Aug 5, 2020
@palpatim palpatim requested review from lawmicha, royjit, drochetti and a team August 5, 2020 18:39
@palpatim palpatim marked this pull request as ready for review August 5, 2020 18:40
@jamesonwilliams jamesonwilliams self-requested a review August 5, 2020 19:42
Copy link
Contributor

@drochetti drochetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of comments for discussion as I'm aware this is time sensitive.

I'll continue the review...

Comment on lines +8 to +9
// No-listener versions of the public APIs, to clean call sites that use Combine
// publishers to get results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little bit confused by this strategy. I understand why the listener is required, but making it optional only on iOS 13 is no guarantee that the developer will consume the result through the Combine publisher, is that fair assumption?

Can we provide these extensions passing nil by default regardless of the iOS version? I believe this would be beneficial for other 3rd party integrations as well, such as PromiseKit. Otherwise we, or the community, will have to write the same extensions for PromiseKit support.

What are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps: one thing that just came to my mind is, JS Promises emits warnings when no listeners are attached to a promise, that could be an interesting DX optimization for nil listeners that weren't resolved anywhere (either by the developer, or by a Combine publisher, or by a PromiseKit Promise)... Just food for thought! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little bit confused by this strategy. I understand why the listener is required, but making it optional only on iOS 13 is no guarantee that the developer will consume the result through the Combine publisher, is that fair assumption?

That is correct.

Can we provide these extensions passing nil by default regardless of the iOS version? I believe this would be beneficial for other 3rd party integrations as well, such as PromiseKit. Otherwise we, or the community, will have to write the same extensions for PromiseKit support.

What are your thoughts on this?

We definitely could. It would mean that customers who don't support iOS 13 would be able to execute operations with no listener, just like Combine-flavored APIs. It would simplify the API surface and bring parity to the party, too, so that's a plus.

The main question would be whether we feel comfortable with giving customers the ability to invoke without a listener, but I'm thinking that might be OK. We've made a pretty strong commitment to the paradigm that "the work being performed by an operation" is separate from "the reporting of the results of the operation", by separating cancellation of the work from cancellation of the subscription.

I think I'm in favor of this and will update.

Copy link
Member Author

@palpatim palpatim Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force-push includes a rebase/squash, and giving default values to nil-listener APIs for all platforms, not just iOS 13.

@palpatim palpatim force-pushed the palpatim/combine-support-take-2 branch 2 times, most recently from dcc166f to 8e8c0b7 Compare August 6, 2020 02:01
- feat: Amplify Category APIs that accept optional listeners now default them
  to `nil`, simplifying the call site
- feat: HubChannel is now Hashable
- feat: Add 'underlying error' constructor to AmplifyError
- chore: Fix OperationTestBase and reenable previously disabled tests
- chore: Change GraphQLOperation and GraphQLSubscriptionOperation to subclasses
  rather than typealiases
@palpatim palpatim force-pushed the palpatim/combine-support-take-2 branch from 8e8c0b7 to e4b12f8 Compare August 10, 2020 18:11
Copy link
Contributor

@drochetti drochetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is huuuuge. Thanks Tim! 🚀

@palpatim palpatim merged commit 8eef5aa into main Aug 12, 2020
@palpatim palpatim deleted the palpatim/combine-support-take-2 branch August 12, 2020 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants