Skip to content

Instantly share code, notes, and snippets.

@GeePawHill
Created December 27, 2023 19:59
Show Gist options
  • Save GeePawHill/fcdea0e919bf1c53aaee78aaca408015 to your computer and use it in GitHub Desktop.
Save GeePawHill/fcdea0e919bf1c53aaee78aaca408015 to your computer and use it in GitHub Desktop.
A sample sketch of an idea in code
/*
Can't say this here, business doesn't know Node
class BlockFactory {
fun nodeFor(block:TextBlock):Node {
Make the correct node given that it's a text block and return it.
}
fun nodeFor(block:TodoBlock):Node {
}
fun nodeFor(block:UsersPageBlock): Node {
}
}
*/
enum class BlockType {
text,
rich,
todo,
users,
}
interface PageBlock {
val type: BlockType
}
@Serializable
data class TextBlock(val text: String) : PageBlock {
override val type: BlockType = BlockType.text
}
@Serializable
data class TodoBlock(val isChecked: Boolean) : PageBlock {
override val type: BlockType = BlockType.todo
}
@Serializable
data class UserEntry(val name: String, val email: String, val somethingElse: String)
@Serializable
data class UsersPageBlock(val page: Int, val users: List<UserEntry>) : PageBlock {
override val type: BlockType = BlockType.users
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment