Created
January 5, 2017 19:22
-
-
Save LewisRhine/aaf2ab191cb2b113d5c75c39198259f0 to your computer and use it in GitHub Desktop.
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
fun mdlApp(init: MdlApp.() -> Unit): MdlApp { | |
val app = MdlApp() | |
app.init() | |
return app | |
} | |
class MdlApp() { | |
private val app = document.getElementById("MdlApp") | |
init { | |
requireNotNull(app) { "No MldApp Element found!" } | |
} | |
fun navigationLayout(content: MdlContent, cssClass: String = "", init: Layout.() -> Unit) { | |
val nl = Layout(content, cssClass) | |
nl.init() | |
nl.mainElement.append(nl.content.content.mainElement) | |
app?.append(nl.mainElement) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can get rid of the manual null check in the
init
block by either specifying the type ofapp
explicitly, without the question mark, or by adding!!
afterdocument.getElementById("MdlApp")
to assert it's not null. After doing this, you can remove the question mark afterapp
on the last line since it can't be null.