Update DataSetBuilder API
This commit is contained in:
parent
e66ae408cd
commit
4d19d97c53
@ -21,3 +21,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readme{
|
||||||
|
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
|
||||||
|
}
|
||||||
|
@ -74,18 +74,6 @@ public suspend fun <T : Any> DataSetBuilder<T>.emit(name: String, data: Data<T>)
|
|||||||
emit(name.toName(), data)
|
emit(name.toName(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend fun <T : Any> DataSetBuilder<T>.data(name: Name, data: T, meta: Meta = Meta.EMPTY) {
|
|
||||||
emit(name, Data.static(data, meta))
|
|
||||||
}
|
|
||||||
|
|
||||||
public suspend fun <T : Any> DataSetBuilder<T>.data(name: Name, data: T, block: MetaBuilder.() -> Unit = {}) {
|
|
||||||
emit(name, Data.static(data, Meta(block)))
|
|
||||||
}
|
|
||||||
|
|
||||||
public suspend fun <T : Any> DataSetBuilder<T>.data(name: String, data: T, block: MetaBuilder.() -> Unit = {}) {
|
|
||||||
emit(name.toName(), Data.static(data, Meta(block)))
|
|
||||||
}
|
|
||||||
|
|
||||||
public suspend fun <T : Any> DataSetBuilder<T>.emit(name: String, set: DataSet<T>) {
|
public suspend fun <T : Any> DataSetBuilder<T>.emit(name: String, set: DataSet<T>) {
|
||||||
this.emit(name.toName(), set)
|
this.emit(name.toName(), set)
|
||||||
}
|
}
|
||||||
@ -97,6 +85,32 @@ public suspend fun <T : Any> DataSetBuilder<T>.emit(data: NamedData<T>) {
|
|||||||
emit(data.name, data.data)
|
emit(data.name, data.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce lazy [Data] and emit it into the [DataSetBuilder]
|
||||||
|
*/
|
||||||
|
public suspend inline fun <reified T : Any> DataSetBuilder<T>.emitLazy(
|
||||||
|
name: String,
|
||||||
|
meta: Meta,
|
||||||
|
noinline producer: suspend () -> T,
|
||||||
|
) {
|
||||||
|
val data = Data(meta, block = producer)
|
||||||
|
emit(name, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit a static data with the fixed value
|
||||||
|
*/
|
||||||
|
public suspend fun <T : Any> DataSetBuilder<T>.emitStatic(name: String, data: T, meta: Meta = Meta.EMPTY): Unit =
|
||||||
|
emit(name, Data.static(data, meta))
|
||||||
|
|
||||||
|
public suspend fun <T : Any> DataSetBuilder<T>.emitStatic(
|
||||||
|
name: String,
|
||||||
|
data: T,
|
||||||
|
metaBuilder: MetaBuilder.() -> Unit,
|
||||||
|
) {
|
||||||
|
emit(name.toName(), Data.static(data, Meta(metaBuilder)))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update data with given node data and meta with node meta.
|
* Update data with given node data and meta with node meta.
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +14,7 @@ class ActionsTest {
|
|||||||
val data: DataTree<Int> = runBlocking {
|
val data: DataTree<Int> = runBlocking {
|
||||||
DataTree {
|
DataTree {
|
||||||
repeat(10) {
|
repeat(10) {
|
||||||
data(it.toString(), it)
|
emitStatic(it.toString(), it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ internal class DataTreeBuilderTest {
|
|||||||
|
|
||||||
val node = DataTree<Any> {
|
val node = DataTree<Any> {
|
||||||
emit("primary") {
|
emit("primary") {
|
||||||
data("a", "a")
|
emitStatic("a", "a")
|
||||||
data("b", "b")
|
emitStatic("b", "b")
|
||||||
}
|
}
|
||||||
data("root", "root")
|
emitStatic("root", "root")
|
||||||
populate(updateData)
|
populate(updateData)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ internal class DataTreeBuilderTest {
|
|||||||
updateJob = launch {
|
updateJob = launch {
|
||||||
repeat(10) {
|
repeat(10) {
|
||||||
delay(10)
|
delay(10)
|
||||||
data("value", it)
|
emitStatic("value", it)
|
||||||
}
|
}
|
||||||
delay(10)
|
delay(10)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class DataPropagationTest {
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
data {
|
data {
|
||||||
repeat(100) {
|
repeat(100) {
|
||||||
data("myData[$it]", it)
|
emitStatic("myData[$it]", it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ class FileDataTest {
|
|||||||
val dataNode = runBlocking {
|
val dataNode = runBlocking {
|
||||||
DataTree<String> {
|
DataTree<String> {
|
||||||
emit("dir") {
|
emit("dir") {
|
||||||
data("a", "Some string") {
|
emitStatic("a", "Some string") {
|
||||||
"content" put "Some string"
|
"content" put "Some string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data("b", "root data")
|
emitStatic("b", "root data")
|
||||||
meta {
|
meta {
|
||||||
"content" put "This is root meta node"
|
"content" put "This is root meta node"
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class SimpleWorkspaceTest {
|
|||||||
|
|
||||||
data {
|
data {
|
||||||
repeat(100) {
|
repeat(100) {
|
||||||
data("myData[$it]", it)
|
emitStatic("myData[$it]", it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user