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

Remove Public Promise #709

Merged
merged 16 commits into from
Sep 16, 2019
Merged

Remove Public Promise #709

merged 16 commits into from
Sep 16, 2019

Conversation

designatednerd
Copy link
Contributor

NOTE: Leaving this as a draft because I'd like @martijnwalraven to take a look at this when he's back from vacation, and I'd love to hear any other feedback in the meantime.

This PR addresses #382. The promises Martijn created were originally intended to only be for framework-internal consumption, not for use by outside apps or SDKs. This is why we're using a custom Promise type rather than existing Promise libraries.

However, our Promise type conflicts with those existing libraries and can cause all sorts of weirdness and confusion when it's exposed publicly, and it also somewhat hamstrings future implementation choices (including removing Promises under the hood entirely).

For this PR, we're only removing the "public" aspect of promises and continuing to use them under the hood. This should give us more flexibility in the future, and make it easier to wrap these methods in their preferred promise library.

Note that this is going to be a BREAKING CHANGE!

@designatednerd designatednerd added this to the 0.16.0 milestone Aug 16, 2019
Copy link
Contributor

@martijnwalraven martijnwalraven left a comment

Choose a reason for hiding this comment

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

Glad to get rid of the publicly exposed Promise implementation! It's a breaking change, but I think it's worth it and it shouldn't impact too many people.

I think the code could be simplified with generic wrapper methods to convert methods from/to the use of promises, but that's probably not worth the trouble.

@@ -258,3 +301,48 @@ public final class ApolloStore {
}
}
}

internal extension NormalizedCache {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably not worth the trouble, but I wonder if we could use something like Node's promisify to avoid writing these wrapper methods manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I'd eventually like to remove our promises system I'm not entirely convinced making them easier to create is worth it. 😆

}.andThen {
fulfill(())
}
guard let completion = completion else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe apollo_performAsyncIfNeeded could be extended with a guard for an optional callback?

public func withinReadTransaction<T>(_ body: @escaping (ReadTransaction) throws -> T,
callbackQueue: DispatchQueue? = nil,
completion: ((Result<T, Error>) -> Void)? = nil) {
_ = self.withinReadTransactionPromise {
Copy link
Contributor

Choose a reason for hiding this comment

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

This may not be worth it, but maybe a generic wrapper method like Node's callbackify could be used to abstract this conversion.


import Foundation

public extension DispatchQueue {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this extension need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in order for it to be usable in the ApolloSQLite framework.

@designatednerd designatednerd force-pushed the rm/public-promise branch 2 times, most recently from 3b8b444 to 9f914e1 Compare September 13, 2019 00:11
@designatednerd designatednerd marked this pull request as ready for review September 16, 2019 18:27
@designatednerd
Copy link
Contributor Author

may [deity or lack thereof of choice] have mercy on us all

@designatednerd designatednerd merged commit 4693ad8 into master Sep 16, 2019
@designatednerd designatednerd deleted the rm/public-promise branch September 16, 2019 22:48
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.

3 participants