Skip to content

Commit

Permalink
Misc cleanup (#146)
Browse files Browse the repository at this point in the history
* LifecycleScopeFactory README example cleanup

* remove duplicate dependency declarations in android-lifecycle gradle config

* android-lifecycle sample annotation consolidation

* lifecycleScope extension sample rename

* MainImmediateCoroutineScope factory function formatting

* update docs
  • Loading branch information
RBusarow authored Jul 12, 2020
1 parent 251aa51 commit af480ca
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 28 deletions.
8 changes: 4 additions & 4 deletions dispatch-android-lifecycle-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SomeApplication : Application() {
override fun onCreate() {
super.onCreate()
// A custom factory can be set to add elements to the CoroutineContext
LifecycleScopeFactory.set { MainImmediateProvidedCoroutineContext() + SomeCustomElement() }
LifecycleScopeFactory.set { MainImmediateContext() + SomeCustomElement() }
}
}
```
Expand All @@ -68,7 +68,7 @@ class SomeEspressoTest {
@After
fun tearDown() {
// The factory can also be reset to default
LifecycleCoroutineScopeFactory.reset()
LifecycleScopeFactory.reset()
}
}
```
Expand All @@ -93,7 +93,7 @@ class SomeFragmentEspressoTest {
fun setUp() {
// set a custom factory which is applied to all newly created lifecycleScopes
LifecycleScopeFactory.set {
MainImmediateProvidedCoroutineContext() + idlingRule.dispatcherProvider
MainImmediateContext() + idlingRule.dispatcherProvider
}

// now SomeFragment will use an IdlingDispatcher in its CoroutineScope
Expand Down Expand Up @@ -142,7 +142,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7")
implementation("com.rickbusarow.dispatch:dispatch-android-lifecycle-extensions:1.0.0-beta04")

implementation("androidx.lifecycle:lifecycle-common:2.2.0")
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package samples
import dispatch.android.lifecycle.*
import dispatch.core.*

class LifecycleScopeSample {
class LifecycleScopeExtensionSample {

@Sample
fun lifecycleScopeSample() {
fun lifecycleScopeExtensionSample() {

// This could be any LifecycleOwner -- Fragments, Activities, Services...
class SomeFragment : Fragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import kotlinx.coroutines.*
* The `viewModelScope` is automatically cancelled when the [LifecycleOwner]'s
* [lifecycle][LifecycleOwner.getLifecycle]'s [Lifecycle.State] drops to [Lifecycle.State.DESTROYED].
*
* @sample samples.LifecycleScopeSample.lifecycleScopeSample
* @sample samples.LifecycleScopeExtensionSample.lifecycleScopeExtensionSample
*/
val LifecycleOwner.lifecycleScope: LifecycleCoroutineScope
get() = LifecycleCoroutineScopeStore.get(this.lifecycle)
3 changes: 0 additions & 3 deletions dispatch-android-lifecycle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,5 @@ dependencies {
testImplementation(Libs.RickBusarow.Hermit.coroutines)
testImplementation(Libs.RickBusarow.Hermit.junit5)

testImplementation(Libs.RickBusarow.Hermit.coroutines)
testImplementation(Libs.RickBusarow.Hermit.junit5)

testImplementation(Libs.Robolectric.core)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* limitations under the License.
*/

@file:Suppress("EXPERIMENTAL_API_USAGE")

package samples

import dispatch.android.lifecycle.*
Expand Down Expand Up @@ -46,7 +44,8 @@ class LifecycleCoroutineScopeFactorySample {
}
}

private annotation class Before
private annotation class After
private annotation class Module
private annotation class Provides
internal annotation class Before
internal annotation class After
internal annotation class Module
internal annotation class Provides
internal annotation class Inject
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*

annotation class Inject

@CoroutineTest
@ExperimentalCoroutinesApi
class LifecycleCoroutineScopeSample(
Expand Down
4 changes: 2 additions & 2 deletions dispatch-core/src/main/java/dispatch/core/CoroutineScopes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public fun MainCoroutineScope(
* @see CoroutineScope
*/
public fun MainImmediateCoroutineScope(
job: Job = SupervisorJob(), dispatcherProvider:
DispatcherProvider = DefaultDispatcherProvider()
job: Job = SupervisorJob(),
dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider()
): MainImmediateCoroutineScope = object : MainImmediateCoroutineScope {
override val coroutineContext = job + dispatcherProvider.mainImmediate +
dispatcherProvider
Expand Down
8 changes: 4 additions & 4 deletions docs/kdoc/dispatch-android-lifecycle-extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SomeApplication : Application() {
override fun onCreate() {
super.onCreate()
// A custom factory can be set to add elements to the CoroutineContext
LifecycleScopeFactory.set { MainImmediateProvidedCoroutineContext() + SomeCustomElement() }
LifecycleScopeFactory.set { MainImmediateContext() + SomeCustomElement() }
}
}
```
Expand All @@ -65,7 +65,7 @@ class SomeEspressoTest {
@After
fun tearDown() {
// The factory can also be reset to default
LifecycleCoroutineScopeFactory.reset()
LifecycleScopeFactory.reset()
}
}
```
Expand All @@ -90,7 +90,7 @@ class SomeFragmentEspressoTest {
fun setUp() {
// set a custom factory which is applied to all newly created lifecycleScopes
LifecycleScopeFactory.set {
MainImmediateProvidedCoroutineContext() + idlingRule.dispatcherProvider
MainImmediateContext() + idlingRule.dispatcherProvider
}

// now SomeFragment will use an IdlingDispatcher in its CoroutineScope
Expand Down Expand Up @@ -139,7 +139,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7")
implementation("com.rickbusarow.dispatch:dispatch-android-lifecycle-extensions:1.0.0-beta04")

implementation("androidx.lifecycle:lifecycle-common:2.2.0")
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/dispatch-android-lifecycle-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SomeApplication : Application() {
override fun onCreate() {
super.onCreate()
// A custom factory can be set to add elements to the CoroutineContext
LifecycleScopeFactory.set { MainImmediateProvidedCoroutineContext() + SomeCustomElement() }
LifecycleScopeFactory.set { MainImmediateContext() + SomeCustomElement() }
}
}
```
Expand All @@ -68,7 +68,7 @@ class SomeEspressoTest {
@After
fun tearDown() {
// The factory can also be reset to default
LifecycleCoroutineScopeFactory.reset()
LifecycleScopeFactory.reset()
}
}
```
Expand All @@ -93,7 +93,7 @@ class SomeFragmentEspressoTest {
fun setUp() {
// set a custom factory which is applied to all newly created lifecycleScopes
LifecycleScopeFactory.set {
MainImmediateProvidedCoroutineContext() + idlingRule.dispatcherProvider
MainImmediateContext() + idlingRule.dispatcherProvider
}

// now SomeFragment will use an IdlingDispatcher in its CoroutineScope
Expand Down Expand Up @@ -142,7 +142,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7")
implementation("com.rickbusarow.dispatch:dispatch-android-lifecycle-extensions:1.0.0-beta04")

implementation("androidx.lifecycle:lifecycle-common:2.2.0")
}
```
Expand Down

0 comments on commit af480ca

Please sign in to comment.