I recently discovered Mithril.js and wanted to give it a shot with an application that's slightly more complicated than the standard ToDo example. I decided on making a simple blogging software. The requirements for the software were as follows:
- A listing of all blog posts as the front page of the app
- The ability to add, edit, and remove posts.
- A combined Add/Edit Form for managing posts
- The usage of localstorage
- Accessing localstorage in a faux asynchronous manner to simulate REST type requests
What follows is the result.
I plan to continue expanding and refining this prototype to continue learning about Mithril, and eventually turn it into a series of blog posts. In the meantime, here is the code I've come up with. It's broken down into several pieces.
- App Router - A file designating the app's routes.
- Posts - A namespace containing the Post model and functions to persist it.
- PostForm - A Mithril module containing the view and controller for the Post Form.
- PostList - A Mithril module containing the view and controller for the Post List.
- Utils - Some helper functions I use in various places.
- Polyfills - A few additions to the Array prototype.
I doubt my organization and patterns are close to solid yet, but I feel I'm on the right track.