Meaning of 'emit' in Android Jetpack Compose

Android Jetpack Compose의 공식 문서에서는 emit이라는 단어가 빈번히 등장합니다. emit방출하다, 내보내다라는 의미를 지니고 있는데 컴포저블에서 내보낸 UI를 누가 처리하는지, 애초에 내보낸다는 표현을 왜 쓰게 되었는지에 대해 명확한 설명이 없어 궁금증을 자아냅니다.

그래서 stackoverflow에 What is the exact meaning of ‘emit’ in Android Jetpack Compose?라는 질문을 올렸고 Composables.kt 내부의 소스 코드에 그에 대한 답이 있다는 것을 알게 되었습니다.

아래는 제 질문과 그에 대한 답변입니다.

Question

The word emit is often used in Jetpack Compose’s documentation or codelabs, as follows:

The function doesn’t return anything. Compose functions that “emit” UI do not need to return anything, because they describe the desired screen state instead of constructing UI widgets.

What is the exact meaning of emit in Android Jetpack Compose?

Who handles the UI emitted by the Compose function? Does the Compose framework detect and process the emitted UI?

Is there documentation with information on how and by whom the emitted UI is handled?

Answer by EpicPandaForce

“Emit” means that Compose inserts a new group into the current composition.

See the source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Suppress("NONREADONLY_CALL_IN_READONLY_COMPOSABLE", "UnnecessaryLambdaCreation")
@Composable inline fun <T : Any, reified E : Applier<*>> ReusableComposeNode(
noinline factory: () -> T,
update: @DisallowComposableCalls Updater<T>.() -> Unit
) {
if (currentComposer.applier !is E) invalidApplier()
currentComposer.startReusableNode() // <--- EMITTING THE NODE
if (currentComposer.inserting) {
currentComposer.createNode { factory() }
} else {
currentComposer.useNode()
}
currentComposer.disableReusing()
Updater<T>(currentComposer).update()
currentComposer.enableReusing()
currentComposer.endNode()
}

댓글