-
Notifications
You must be signed in to change notification settings - Fork 500
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
Mavericks Extensions argsOrNull #639
Mavericks Extensions argsOrNull #639
Conversation
Codecov Report
@@ Coverage Diff @@
## main #639 +/- ##
==========================================
- Coverage 55.06% 49.43% -5.63%
==========================================
Files 53 54 +1
Lines 2508 2846 +338
Branches 326 338 +12
==========================================
+ Hits 1381 1407 +26
- Misses 976 1284 +308
- Partials 151 155 +4
Continue to review full report at Codecov.
|
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.
@elihart This seems like a reasonable addition to me. Wdyt?
* creating a key for each one. | ||
* | ||
* To create nullable arguments, define a property in your fragment like: | ||
* `private val listingId by argsOrNull<MyArgs?>()` |
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.
* `private val listingId by argsOrNull<MyArgs?>()` | |
* `private val listingId: MyArgs? by argsOrNull()` |
Can you update the doc above, too?
* | ||
* Each fragment can only have a single argument with the key [Mavericks.KEY_ARG] | ||
*/ | ||
fun <V : Any> argsOrNull() = object : ReadOnlyProperty<Fragment, V?> { |
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.
fun <V : Any> argsOrNull() = object : ReadOnlyProperty<Fragment, V?> { | |
fun <V> argsOrNull() = object : ReadOnlyProperty<Fragment, V?> { |
I think you can safely emit the type narrowing since the return type is nullable.
@elihart what do you think of |
sure, seems helpful. only comment is that it would be nice to have a test |
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.
Thanks!
Adding Mavericks Extensions argsOrNull which can be useful for those cases where you have an optional argument that might be sent or not.
As an example, imagine a shared screen / flow from different entry points. While this can be fixed in multiple ways in the client's code having an explicit enum that represents null / empty / none it ends up being more code which ultimately represents the same thing (although this introduces the option of nullable arguments which can also be seen as a downside)
Thoughts?