Skip to content

Commit

Permalink
Described Essenty scoping extensions in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Dec 27, 2023
1 parent b478453 commit bcb0fc9
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions docs/component/scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ Due to the fact that components are lifecycle-aware, it is very easy to manage c

## Creating a CoroutineScope in a component

```kotlin
fun CoroutineScope(context: CoroutineContext, lifecycle: Lifecycle): CoroutineScope {
val scope = CoroutineScope(context)
lifecycle.doOnDestroy(scope::cancel)
return scope
}
!!! note "Extensions for CoroutineScope and Lifecycle"

fun LifecycleOwner.coroutineScope(context: CoroutineContext): CoroutineScope =
CoroutineScope(context, lifecycle)
=== "Before Essenty 2.0.0-alpha01"

```kotlin
fun CoroutineScope(context: CoroutineContext, lifecycle: Lifecycle): CoroutineScope {
val scope = CoroutineScope(context)
lifecycle.doOnDestroy(scope::cancel)
return scope
}
fun LifecycleOwner.coroutineScope(context: CoroutineContext): CoroutineScope =
CoroutineScope(context, lifecycle)
```

=== "Since Essenty 2.0.0-alpha01"

Since Essenty version `2.0.0-alpha01` extensions for `CoroutineScope` and `Lifecycle` are [provided](https://github.com/arkivanov/Essenty?tab=readme-ov-file#coroutines-extensions) by Essenty.

```kotlin
class SomeComponent(
componentContext: ComponentContext,
mainContext: CoroutineContext,
Expand Down Expand Up @@ -65,16 +75,26 @@ class SomeComponent(

## Creating a Reaktive DisposableScope in a component

```kotlin
fun DisposableScope(lifecycle: Lifecycle): DisposableScope {
val scope = DisposableScope()
lifecycle.doOnDestroy(scope::dispose)
return scope
}
!!! note "Extensions for DisposableScope and Lifecycle"

fun LifecycleOwner.disposableScope(): DisposableScope =
DisposableScope(lifecycle)
=== "Before Essenty 2.0.0-alpha01"

```kotlin
fun DisposableScope(lifecycle: Lifecycle): DisposableScope {
val scope = DisposableScope()
lifecycle.doOnDestroy(scope::dispose)
return scope
}
fun LifecycleOwner.disposableScope(): DisposableScope =
DisposableScope(lifecycle)
```

=== "Since Essenty 2.0.0-alpha01"

Since Essenty version `2.0.0-alpha01` extensions for `DisposableScope` and `Lifecycle` are [provided](https://github.com/arkivanov/Essenty?tab=readme-ov-file#reaktive-extensions) by Essenty.

```kotlin
class SomeComponent(
componentContext: ComponentContext,
) : ComponentContext by componentContext,
Expand Down

0 comments on commit bcb0fc9

Please sign in to comment.