Skip to content

Instantly share code, notes, and snippets.

@kulakowka
Created March 3, 2016 13:09
Show Gist options
  • Save kulakowka/bec2ec42c125f7bd4795 to your computer and use it in GitHub Desktop.
Save kulakowka/bec2ec42c125f7bd4795 to your computer and use it in GitHub Desktop.
How to create different layouts for Mithril.js
import m from 'mithril'
// Function for compose header and footer into layout
function mixinLayout (layout, header, footer, body) {
return layout(header, footer, body)
}
// Layout component
function layout (header, footer, body) {
return {
view () {
return [
m.component(header),
m.component(body),
m.component(footer)
]
}
}
}
// Header component
const Header = {
view () {
return <header>Sitename</header>
}
}
// Footer component
const Footer = {
view () {
return <footer>Sitename</footer>
}
}
// Create main layouts
const mainLayout = mixinLayout.bind(null, layout, header, footer)
const routes = {
'/': mainLayout(Homepage),
'/articles': mainLayout(ArticlesIndex),
'/articles/:id': mainLayout(ArticleShow)
}
m.route(document.body, '/', routes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment