-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Convert FIRGetOptions.initWithSource to factory method. (#655) #711
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
Conversation
@@ -62,7 +65,7 @@ typedef NS_ENUM(NSUInteger, FIRGetSource) { | |||
/** | |||
* Initializes the get options with the specified source. | |||
*/ | |||
- (instancetype)initWithSource:(FIRGetSource)source NS_SWIFT_NAME(init(source:)); | |||
+ (instancetype)source:(FIRGetSource)source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should lead with their return type in Objective-C
This should be optionsWithSource:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the delay in review!
@@ -62,7 +65,7 @@ typedef NS_ENUM(NSUInteger, FIRGetSource) { | |||
/** | |||
* Initializes the get options with the specified source. | |||
*/ | |||
- (instancetype)initWithSource:(FIRGetSource)source NS_SWIFT_NAME(init(source:)); | |||
+ (instancetype)optionsWithSource:(FIRGetSource)source NS_SWIFT_NAME(source(source:)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think leaving this as a constructor would be good instead of fighting against the translator: GetOptions(source: .cache)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the issue is that we're going to add a timeout too.
In the other languages you'll be able to do things like this:
GetOptions.source(GetOptions.Source.CACHE).timeout(2, TimeUnit.MINUTES);
GetOptions.timeout(2, TimeUnit.MINUTES).source(GetOptions.Source.CACHE);
Making this an initializer only thing means that the same flexibility would require us to define all the permutations of options which doesn't seem like what we want to do at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh okay, that makes sense. This wouldn't solve it entirely though, would it? You'd be left with an instance instead and unable to call the next class method. Unless each option was a constructor and a function:
class func source(_ source: GetSource) -> GetOptions
class func timeout(_ value: Int, _ unit: TimeUnit) -> GetOptions
func source(_ source: GetSource) -> GetOptions
func timeout(_ value: Int, _ unit: TimeUnit) -> GetOptions
Do you mean to have this as an instance method, or am I missing something?
It's worth noting that this could potentially go away once we have the mechanism to ship native Swift files:
public func init(source: GetOptions.Source = .default,
timeout: (Int, TimeUnit) = (2, .minutes))
{ // (or have Timeout as its own type)
// Implementation
}
// Usage:
GetOptions()
GetOptions(source: .cache)
GetOptions(timeout: (5, .seconds))
GetOptions(source: .cache, timeout: (8, .seconds))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think the idea would be to add instance methods as appropriate to allow chaining.
I like the idea of (eventually) using named parameters. (There's a concern if we ever have a very large number of options, but I don't think that's the case here.) Is there an approx timeline for being able to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the API with one minor change to match SnapshotOptions
: remove the argument label to make it source(_:)
, which turns the usage into: GetSource.source(.cache)
. I would be interested to see how it's going to expand with multiple parameters though - class and instance functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; ptal.
(And yeah; expected path forward is to expand with class and instance functions.)
No description provided.