Skip to content

Instantly share code, notes, and snippets.

@LewisRhine
Created January 5, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LewisRhine/aaf2ab191cb2b113d5c75c39198259f0 to your computer and use it in GitHub Desktop.
Save LewisRhine/aaf2ab191cb2b113d5c75c39198259f0 to your computer and use it in GitHub Desktop.
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)
}
}
@LouisCAD
Copy link

LouisCAD commented Feb 6, 2017

You can get rid of the manual null check in the init block by either specifying the type of app explicitly, without the question mark, or by adding !! after document.getElementById("MdlApp") to assert it's not null. After doing this, you can remove the question mark after app on the last line since it can't be null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment