Hauberk
Mithril.js is awesome, but composition can be tricky.
Hauberk aims to change that by allowing the developer to generate reusable, configurable mithril components with as minimal of an API surface area as possible.
// Example Posts.js {} Postscontroller = Hauberk Postsview =
The entire API consists of 5 methods, and if I can come up with a way to collapse it more, I will.
Hauberk.controller
Hauberk.view
Hauberk.controller.mixin
Hauberk.view.mixin
Hauberk.component
### Hauberk.controller(fn, fn1, ...fnN)
Creates a composable controller function of any arity.
```javascript
const API = {
fetch: Hauberk.controller( function (ctrl, url) {
ctrl.data = API.fetch(url)
// ctrl is an accumulator, so we do not need to return it
})
}
const Dashboard = {
controller: Hauberk.controller(
API.fetch('/metrics')
)
view: App(
Header('dashboard'),
Display(Metrics)
)
}
Hauberk.view(fn, fn1, ...fnN)
Creates a composable view function of any arity
Hauberk.controller.mixin(fn, fn1, ...fnN)
Hauberk.view.mixin(fn)
const Layout = Hauberkview const Header = Hauberkview const Dashboard = controller: Hauberk view:
Hauberk.component(Class, config)
returns a function that mithril can invoke to generate a mithril component
//example ./components/Tags.js static { return Object } static { return } // simple example usage Hauberk