Refactor `LoadUrlUseCase.invoke` to be an operator function
Categories
(Firefox for Android :: Browser Engine, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox134 | --- | fixed |
People
(Reporter: lina, Assigned: anpopa, Mentored)
Details
(Keywords: good-first-bug)
Attachments
(1 file)
|
Bug 1851037 - changed fun to operator fun and refactored all callers to avoid explicitly call invoke
48 bytes,
text/x-phabricator-request
|
Details | Review |
The LoadUrlUseCase.invoke method in the feature-session Android Component is declared as a regular fun, not an operator fun. That means we must invoke it explicitly, like this:
loadUrlUseCase.invoke(url)
If we declared invoke as an operator fun, we could invoke it using the more convenient function call syntax instead:
loadUrlUseCase(url)
For this bug, let's:
- Change the declaration of
invoketo useoperator fun. - Ensure that all implementations of
LoadUrlUseCaseuseoverride operator fun. - Refactor all callers in all components to use the more convenient function call syntax, instead of explicitly calling
.invoke().
This is a great first bug for getting started with Android and Kotlin development!
Comment 1•2 years ago
|
||
For the point 3:
It may not possible do something like usecase?() in kotlin 1 .
Alternative way
usecase?.let { it() }
IMHO, invoke() looks better .
Ref: https://discuss.kotlinlang.org/t/cannot-use-the-invoke-operator-after-a-non-null-check/17830/4
Ref: https://youtrack.jetbrains.com/issue/KT-4113
| Reporter | ||
Comment 2•2 years ago
|
||
Thanks for noting that, and for the links; that's really good to know!
IMHO,
invoke()looks better .
I think so, too 😊 Let's leave the nullable calls as usecase?.invoke(), but switch to usecase() for non-nullable calls—how does that sound?
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 3•11 months ago
|
||
Updated•11 months ago
|
Comment 5•11 months ago
|
||
Backed out for causing failures at TabsUseCasesTest.kt.
Backout link: https://hg.mozilla.org/integration/autoland/rev/70bdae77d7e8dc621fc05cbc470f2aa7b34e06e2
Failure log: https://treeherder.mozilla.org/logviewer?job_id=481447258&repo=autoland&lineNumber=25380
| Assignee | ||
Updated•10 months ago
|
Description
•