Skip to content

Commit

Permalink
refactor: return modified state for space and block builders
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Nov 17, 2023
1 parent 41c7eee commit 0286dcb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class BlockContext internal constructor(
}
}

public suspend fun SpaceContext.block(configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.block(configure: suspend BlockContext.() -> Unit): Block {
val space = space.id

log.i {
Expand All @@ -104,72 +104,60 @@ public suspend fun SpaceContext.block(configure: suspend BlockContext.() -> Unit
)

context.configure()

return context.block
}

public suspend fun SpaceContext.sizedBlock(size: BlockSize, configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.sizedBlock(size: BlockSize, configure: suspend BlockContext.() -> Unit): Block =
block {
setSize {
size
}

configure()
}
}

public suspend fun SpaceContext.sizedBlockWithEntities(
size: BlockSize,
row: RowIndex? = null,
configureEntities: suspend ContentEntitiesBuilder.() -> Unit
) {
): Block =
sizedBlock(size) {
row?.let {
setRow { it }
}

setEntities(configureEntities)
}
}

public suspend fun SpaceContext.smallBlock(configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.smallBlock(configure: suspend BlockContext.() -> Unit): Block =
sizedBlock(size = BlockSize.SMALL, configure)
}

public suspend fun SpaceContext.mediumBlock(configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.mediumBlock(configure: suspend BlockContext.() -> Unit): Block =
sizedBlock(size = BlockSize.MEDIUM, configure)
}

public suspend fun SpaceContext.largeBlock(configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.largeBlock(configure: suspend BlockContext.() -> Unit): Block =
sizedBlock(size = BlockSize.LARGE, configure)
}

public suspend fun SpaceContext.extraLargeBlock(configure: suspend BlockContext.() -> Unit) {
public suspend fun SpaceContext.extraLargeBlock(configure: suspend BlockContext.() -> Unit): Block =
sizedBlock(size = BlockSize.EXTRA_LARGE, configure)
}

public suspend fun SpaceContext.smallBlockWithEntities(
row: RowIndex? = null,
configureEntities: suspend ContentEntitiesBuilder.() -> Unit
) {
sizedBlockWithEntities(size = BlockSize.SMALL, row, configureEntities)
}
): Block = sizedBlockWithEntities(size = BlockSize.SMALL, row, configureEntities)

public suspend fun SpaceContext.mediumBlockWithEntities(
row: RowIndex? = null,
configureEntities: suspend ContentEntitiesBuilder.() -> Unit
) {
sizedBlockWithEntities(size = BlockSize.MEDIUM, row, configureEntities)
}
): Block = sizedBlockWithEntities(size = BlockSize.MEDIUM, row, configureEntities)

public suspend fun SpaceContext.largeBlockWithEntities(
row: RowIndex? = null,
configureEntities: suspend ContentEntitiesBuilder.() -> Unit
) {
sizedBlockWithEntities(size = BlockSize.LARGE, row, configureEntities)
}
): Block = sizedBlockWithEntities(size = BlockSize.LARGE, row, configureEntities)

public suspend fun SpaceContext.extraLargeBlockWithEntities(
row: RowIndex? = null,
configureEntities: suspend ContentEntitiesBuilder.() -> Unit
) {
sizedBlockWithEntities(size = BlockSize.EXTRA_LARGE, row, configureEntities)
}
): Block = sizedBlockWithEntities(size = BlockSize.EXTRA_LARGE, row, configureEntities)
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public suspend fun ApplicationContext.space(
spaceIdentifier: SpaceIdentifier = ROOT_SPACE_SLUG,
processBlocks: Boolean = true,
configure: suspend SpaceContext.() -> Unit
) {
): Space {
var space = client.getSpace(spaceIdentifier).getOrNull()

if (space == null) {
Expand Down Expand Up @@ -142,6 +142,8 @@ public suspend fun ApplicationContext.space(
val context = SpaceContext(space, processBlocks, client)

context.configure()

return context.space
}

public suspend fun SpaceContext.row(
Expand Down

0 comments on commit 0286dcb

Please sign in to comment.