Skip to content

Commit 9774430

Browse files
committed
fix(modelql): renamed mapLocal2 to buildLocalMapping
1 parent 50f5eec commit 9774430

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

docs/global/modules/core/pages/howto/modelql.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The body of `mapLocal` is executed on the client after receiving the result from
118118
That's why you only have access to the output of the `zip` operation
119119
and still have to use `first`, `second` and `third` inside the query.
120120

121-
To make this even more readable there is a `mapLocal2` operation,
121+
To make this even more readable there is a `buildLocalMapping` operation,
122122
which provides a different syntax for the `zip`-`mapLocal` chain.
123123

124124
[source,kotlin]
@@ -127,6 +127,7 @@ data class MyProduct(val id: Int, val title: String, val images: List<MyImage>)
127127
data class MyImage(val url: String)
128128

129129
val result: List<MyProduct> = query { db ->
130+
db.products.buildLocalMapping {
130131
val id = it.id.request()
131132
val title = it.title.request()
132133
val images = it.images.mapLocal { MyImage(it) }.toList().request()
@@ -138,7 +139,7 @@ val result: List<MyProduct> = query { db ->
138139
result.forEach { println("ID: ${it.id}, Title: ${it.title}, Images: ${it.images}") }
139140
--
140141

141-
At the beginning of the `mapLocal2` body you invoke `request()` on all the values you need to assemble your object.
142+
At the beginning of the `buildLocalMapping` body you invoke `request()` on all the values you need to assemble your object.
142143
This basically ads the operand to the internal `zip` operation and returns an object that gives you access to the value
143144
after receiving it from the server.
144145
Inside the `onSuccess` block you assemble the local object using the previously requested values.
@@ -185,5 +186,5 @@ val html = query {
185186
}
186187
--
187188

188-
`buildHtmlQuery` and the `requestFragment` operation are similar to the `mapLocal2` operation,
189+
`buildHtmlQuery` and the `requestFragment` operation are similar to the `buildLocalMapping` operation,
189190
but inside the `onSuccess` block you use the Kotlin HTML DSL.

modelql-core/src/commonMain/kotlin/org/modelix/modelql/core/LocalMappingStep.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,24 @@ class ExecuteLocalStep<In, Out>(transformation: (In) -> Out) : LocalMappingStep<
107107
}
108108
}
109109

110+
@Deprecated("renamed to buildLocalMapping", ReplaceWith("buildLocalMapping(body)"))
110111
fun <In, Out> IFluxStep<In>.mapLocal2(body: ILocalMappingBuilder<In, Out>.(IMonoStep<In>) -> Unit): IFluxStep<Out> {
111-
return map { it.mapLocal2(body) }
112+
return buildLocalMapping(body)
112113
}
113114

115+
fun <In, Out> IFluxStep<In>.buildLocalMapping(body: ILocalMappingBuilder<In, Out>.(IMonoStep<In>) -> Unit): IFluxStep<Out> {
116+
return map { it.buildLocalMapping(body) }
117+
}
118+
119+
@Deprecated("renamed to buildLocalMapping", ReplaceWith("buildLocalMapping(body)"))
114120
fun <In, Out> IMonoStep<In>.mapLocal2(body: ILocalMappingBuilder<In, Out>.(IMonoStep<In>) -> Unit): IMonoStep<Out> {
121+
return buildLocalMapping(body)
122+
}
123+
124+
fun <In, Out> IMonoStep<In>.buildLocalMapping(body: ILocalMappingBuilder<In, Out>.(IMonoStep<In>) -> Unit): IMonoStep<Out> {
115125
val builder = LocalMappingBuilder<In, Out>()
116126
builder.apply {
117-
body(this@mapLocal2)
127+
body(this@buildLocalMapping)
118128
}
119129
return builder.compileProcessingOutputStep()
120130
}

modelql-core/src/commonTest/kotlin/org/modelix/modelql/core/ModelQLTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class ModelQLTest {
250250
@Test
251251
fun testMapLocal2_unusedInput() = runTestWithTimeout {
252252
val result = remoteProductDatabaseQuery { db ->
253-
db.products.mapLocal2 {
253+
db.products.buildLocalMapping {
254254
val title = "xxx".asMono().getLater()
255255
onSuccess {
256256
"Title: " + title.get()
@@ -262,9 +262,9 @@ class ModelQLTest {
262262
}
263263

264264
@Test
265-
fun testMapLocal2() = runTestWithTimeout {
265+
fun testLocalMappingBuilder() = runTestWithTimeout {
266266
val result = remoteProductDatabaseQuery { db ->
267-
db.products.mapLocal2 {
267+
db.products.buildLocalMapping {
268268
val title = it.title.getLater()
269269
onSuccess {
270270
"Title: " + title.get()
@@ -278,7 +278,7 @@ class ModelQLTest {
278278
@Test
279279
fun testZipOrder() = runTestWithTimeout {
280280
val result = remoteProductDatabaseQuery { db ->
281-
db.products.flatMap { it.zip(it.images.assertNotEmpty()) }.mapLocal2 {
281+
db.products.flatMap { it.zip(it.images.assertNotEmpty()) }.buildLocalMapping {
282282
val product = it.first.getLater()
283283
val image = it.second.getLater()
284284
onSuccess {

0 commit comments

Comments
 (0)