android / android/architecture-samples

[master] ServiceLocator.kt redundant code ?

Open
#674 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
45.8k
Forks
11.9k
PR merge metrics
No merged PRs in 30d

Description

In [app/src/mock/java/com/example/android/architecture/blueprints/todoapp/ServiceLocator.kt](https://github.com/googlesamples/android-architecture/blob/master/app/src/mock/java/com/example/android/architecture/blueprints/todoapp/ServiceLocator.kt),L43. Why repeat `tasksRepository ?:` in return?

Can the return be simplified as `return tasksRepository ?: createTasksRepository(context)` ?

```kotlin
fun provideTasksRepository(context: Context): TasksRepository {
synchronized(this) {
return tasksRepository ?: tasksRepository ?: createTasksRepository(context) // HERE!
}
}
```

Thanks for your attention.

Contributor guide

Open the contributing guide

Research direction

Open app/src/mock/java/com/example/android/architecture/blueprints/todoapp/ServiceLocator.kt and inspect line 43 in provideTasksRepository. Confirm whether the repeated tasksRepository ?: is redundant, then simplify the return expression if appropriate; the work is done when the duplicate expression is removed without changing repository creation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Refactor
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.