Created
December 27, 2023 19:59
-
-
Save GeePawHill/fcdea0e919bf1c53aaee78aaca408015 to your computer and use it in GitHub Desktop.
A sample sketch of an idea in code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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