Update output types of DataTree builders

This commit is contained in:
Alexander Nozik 2022-07-02 19:34:58 +03:00
parent 9a24e1e392
commit 6ca76cff17
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357

View File

@ -21,8 +21,7 @@ public interface DataSourceBuilder<T : Any> : DataSetBuilder<T>, DataSource<T> {
/** /**
* A mutable [DataTree] that propagates updates * A mutable [DataTree] that propagates updates
*/ */
@PublishedApi public class DataTreeBuilder<T : Any>(
internal class DataTreeBuilder<T : Any>(
override val dataType: KType, override val dataType: KType,
coroutineContext: CoroutineContext, coroutineContext: CoroutineContext,
) : DataTree<T>, DataSourceBuilder<T> { ) : DataTree<T>, DataSourceBuilder<T> {
@ -35,7 +34,7 @@ internal class DataTreeBuilder<T : Any>(
override val items: Map<NameToken, DataTreeItem<T>> override val items: Map<NameToken, DataTreeItem<T>>
get() = treeItems.filter { !it.key.body.startsWith("@") } get() = treeItems.filter { !it.key.body.startsWith("@") }
override val updates = MutableSharedFlow<Name>() override val updates: MutableSharedFlow<Name> = MutableSharedFlow<Name>()
@Synchronized @Synchronized
private fun remove(token: NameToken) { private fun remove(token: NameToken) {
@ -102,22 +101,18 @@ public fun <T : Any> DataSource(
type: KType, type: KType,
parent: CoroutineScope, parent: CoroutineScope,
block: DataSourceBuilder<T>.() -> Unit, block: DataSourceBuilder<T>.() -> Unit,
): DataSourceBuilder<T> { ): DataTreeBuilder<T> = DataTreeBuilder<T>(type, parent.coroutineContext).apply(block)
val tree = DataTreeBuilder<T>(type, parent.coroutineContext)
tree.block()
return tree
}
@Suppress("OPT_IN_USAGE","FunctionName") @Suppress("OPT_IN_USAGE","FunctionName")
public inline fun <reified T : Any> DataSource( public inline fun <reified T : Any> DataSource(
parent: CoroutineScope, parent: CoroutineScope,
crossinline block: DataSourceBuilder<T>.() -> Unit, crossinline block: DataSourceBuilder<T>.() -> Unit,
): DataSourceBuilder<T> = DataSource(typeOf<T>(), parent) { block() } ): DataTreeBuilder<T> = DataSource(typeOf<T>(), parent) { block() }
@Suppress("FunctionName") @Suppress("FunctionName")
public suspend inline fun <reified T : Any> DataSource( public suspend inline fun <reified T : Any> DataSource(
crossinline block: DataSourceBuilder<T>.() -> Unit = {}, crossinline block: DataSourceBuilder<T>.() -> Unit = {},
): DataSourceBuilder<T> = DataTreeBuilder<T>(typeOf<T>(), coroutineContext).apply { block() } ): DataTreeBuilder<T> = DataTreeBuilder<T>(typeOf<T>(), coroutineContext).apply { block() }
public inline fun <reified T : Any> DataSourceBuilder<T>.emit( public inline fun <reified T : Any> DataSourceBuilder<T>.emit(
name: Name, name: Name,