Created
March 3, 2016 13:09
-
-
Save kulakowka/bec2ec42c125f7bd4795 to your computer and use it in GitHub Desktop.
How to create different layouts for Mithril.js
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
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