# AbstractApplier

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/Applier.kt+class:androidx.compose.runtime.AbstractApplier) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  abstract class AbstractApplier<T : Any?> : Applier<T>
  ```
Known direct subclasses [VectorApplier](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/vector/VectorApplier)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/vector/VectorApplier` |   |

*** ** * ** ***

An abstract `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier` implementation.

```kotlin
import androidx.compose.runtime.AbstractApplier
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ComposeNode
import androidx.compose.runtime.Composition
import androidx.compose.runtime.CompositionContext
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember

// Provided we have a tree with a node base type like the following
abstract class Node {
    val children = mutableListOf<Node>()
}

// We would implement an Applier class like the following, which would teach compose how to
// manage a tree of Nodes.
class NodeApplier(root: Node) : AbstractApplier<Node>(root) {
    override fun insertTopDown(index: Int, instance: Node) {
        current.children.add(index, instance)
    }

    override fun insertBottomUp(index: Int, instance: Node) {
        // Ignored as the tree is built top-down.
    }

    override fun remove(index: Int, count: Int) {
        current.children.remove(index, count)
    }

    override fun move(from: Int, to: Int, count: Int) {
        current.children.move(from, to, count)
    }

    override fun onClear() {
        root.children.clear()
    }
}

// A function like the following could be created to create a composition provided a root Node.
fun Node.setContent(parent: CompositionContext, content: @Composable () -> Unit): Composition {
    return Composition(NodeApplier(this), parent).apply { setContent(content) }
}

// assuming we have Node sub-classes like "TextNode" and "GroupNode"
class TextNode : Node() {
    var text: String = ""
    var onClick: () -> Unit = {}
}
class GroupNode : Node()

// Composable equivalents could be created
@Composable
fun Text(text: String, onClick: () -> Unit = {}) {
    ComposeNode<TextNode, NodeApplier>(::TextNode) {
        set(text) { this.text = it }
        set(onClick) { this.onClick = it }
    }
}

@Composable
fun Group(content: @Composable () -> Unit) {
    ComposeNode<GroupNode, NodeApplier>(::GroupNode, {}, content)
}

// and then a sample tree could be composed:
fun runApp(root: GroupNode, parent: CompositionContext) {
    root.setContent(parent) {
        var count by remember { mutableStateOf(0) }
        Group {
            Text("Count: $count")
            Text("Increment") { count++ }
        }
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composer` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ComposeNode.composable#ComposeNode(kotlin.Function0,kotlin.Function1)` |   |

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#AbstractApplier(kotlin.Any)(root: T)` | Cmn |

| ### Public functions |
|---|---|---|
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#clear()()` Move to the root and remove all nodes from the root, preparing both this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier` and its root to be used as the target of a new composition in the future. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#down(kotlin.Any)(node: T)` Indicates that the applier is getting traversed "down" the tree. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#up()()` Indicates that the applier is getting traversed "up" the tree. | Cmn |

| ### Protected functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#(kotlin.collections.MutableList).move(kotlin.Int,kotlin.Int,kotlin.Int)(from: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, to: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | Cmn |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#onClear()()` Called to perform clearing of the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#root()` when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#clear()` is called. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#(kotlin.collections.MutableList).remove(kotlin.Int,kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | Cmn |

| ### Public properties |
|---|---|---|
| `open T` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#current()` The node that operations will be applied on at any given time. | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#root()` | Cmn |

### Inherited functions

From [androidx.compose.runtime.Applier](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#apply(kotlin.Function2,kotlin.Any)(block: T.(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)`

Apply a change to the current node.
Cmn `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertBottomUp(kotlin.Int,kotlin.Any)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, instance: T)`

Indicates that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertBottomUp(kotlin.Int,kotlin.Any)` should be inserted as a child of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` at `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertBottomUp(kotlin.Int,kotlin.Any)`.
Cmn `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertTopDown(kotlin.Int,kotlin.Any)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, instance: T)`

Indicates that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertTopDown(kotlin.Int,kotlin.Any)` should be inserted as a child to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` at `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#insertTopDown(kotlin.Int,kotlin.Any)`.
Cmn `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#move(kotlin.Int,kotlin.Int,kotlin.Int)(from: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, to: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Indicates that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#move(kotlin.Int,kotlin.Int,kotlin.Int)` children of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` should be moved from index `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#move(kotlin.Int,kotlin.Int,kotlin.Int)` to index `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#move(kotlin.Int,kotlin.Int,kotlin.Int)`.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#onBeginChanges()()`

Called when the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composer` is about to begin applying changes using this applier.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#onEndChanges()()`

Called when the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composer` is finished applying changes using this applier.
Cmn `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#remove(kotlin.Int,kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Indicates that the children of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#remove(kotlin.Int,kotlin.Int)` to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#remove(kotlin.Int,kotlin.Int)` + `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#remove(kotlin.Int,kotlin.Int)` should be removed.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#reuse()()`

Notify `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` is is being reused in reusable content.
Cmn

## Public constructors

### AbstractApplier

Cmn

```
<T : Any?> AbstractApplier(root: T)
```

## Public functions

### clear

Cmn

```
final fun clear(): Unit
```

Move to the root and remove all nodes from the root, preparing both this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier` and its root to be used as the target of a new composition in the future.

### down

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun down(node: T): Unit
```

Indicates that the applier is getting traversed "down" the tree. When this gets called, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#down(kotlin.Any)` is expected to be a child of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()`, and after this operation, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#down(kotlin.Any)` is expected to be the new `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()`.

### up

Cmn

```
open fun up(): Unit
```

Indicates that the applier is getting traversed "up" the tree. After this operation completes, the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` should return the "parent" of the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#current()` node at the beginning of this operation.

## Protected functions

### MutableList.move

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/Applier.kt+function:move) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
protected fun MutableList<T>.move(from: Int, to: Int, count: Int): Unit
```

### onClear

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
protected abstract fun onClear(): Unit
```

Called to perform clearing of the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#root()` when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/AbstractApplier#clear()` is called.

### MutableList.remove

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/Applier.kt+function:remove) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
protected fun MutableList<T>.remove(index: Int, count: Int): Unit
```

## Public properties

### current

Cmn

```
open var current: T
```

The node that operations will be applied on at any given time. It is expected that the value of this property will change as `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#down(kotlin.Any)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Applier#up()` are called.

### root

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val root: T
```