Skip to content
Prev Previous commit
Next Next commit
[Crane] Adds comments clarifyng singletons
  • Loading branch information
Manuel Vivo committed Oct 20, 2020
commit 74a83bca65296368e8a3de42bedebfa718ce08b1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package androidx.compose.samples.crane.di

import android.os.AsyncTask
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.asCoroutineDispatcher

@OptIn(ExperimentalCoroutinesApi::class)
@Module
Expand All @@ -33,5 +34,6 @@ class TestDispatchersModule {

@Provides
@DefaultDispatcher
fun provideDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Unconfined
fun provideDefaultDispatcher(): CoroutineDispatcher =
AsyncTask.THREAD_POOL_EXECUTOR.asCoroutineDispatcher()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@

package androidx.compose.samples.crane.data

import androidx.compose.samples.crane.calendar.model.CalendarDay
import androidx.compose.samples.crane.calendar.model.CalendarMonth
import androidx.compose.samples.crane.calendar.model.DayOfWeek
import javax.inject.Inject
import javax.inject.Singleton

typealias CalendarYear = List<CalendarMonth>

/**
* Annotated with Singleton because [CalendarDay] contains mutable state.
*/
@Singleton
class DatesLocalDataSource @Inject constructor() {

private val january2020 = CalendarMonth(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

// Marked as Singleton as it contains mutable state
/**
* Annotated with Singleton because [DatesSelectedState] contains mutable state.
*/
@Singleton
class DatesRepository @Inject constructor(
datesLocalDataSource: DatesLocalDataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import javax.inject.Singleton

private const val DEFAULT_IMAGE_WIDTH = "250"

/**
* Annotated with Singleton as the class created a lot of objects.
*/
@Singleton
class DestinationsLocalDataSource @Inject constructor() {

Expand Down