Mithril 是一个客户端的 JavaScript MVC 框架。可将应用分成数据层、UI层和控制层。Mithril 压缩后只有 3kb 左右。API 提供一个模板引擎,带 DOM diff 实现,支持路由和组合。
示例:
//namespace
var app = {};
//model
app.PageList = function() {
return m.request({method: "GET", url: "pages.json"});
};
//controller
app.controller = function() {
this.pages = app.PageList();
};
//view
app.view = function(ctrl) {
return ctrl.pages().map(function(page) {
return m("a", {href: page.url}, page.title);
});
};
//initialize
m.module(document.getElementById("example"), app);
性能比较:
Mithril 0.1.21 发布,此版本是个维护版本,现已提供下载。更新内容如下:
新特性:
passing a promise to an m.prop now populates it with the resolved value upon resolution, and returns undefined otherwise
m.redraw can now be forced to called synchronously
Bug 修复:
fixed handling of + character in m.route.param #204
fixed corner case for undefined children in diff #206
fixed context.onunload for array items #200
fixed handling on comments in HTML converter tool