JavaScript 的 MVC 框架,Mithril 0.1.22 发布

jopen 9年前

Mithril.js 是一个客户端的MVC框架 - 一个工具来组织代码的方式,使其更容易理解和维护。API 提供一个模板引擎,带 DOM diff 实现,支持路由和组合。

轻量级

  • Only 5kb gzipped, no dependencies
  • Small API, small learning curve

健壮

  • Safe-by-default templates
  • Hierarchical MVC via components

快速

  • Virtual DOM diffing and compilable templates
  • Intelligent auto-redrawing system

Mithril 0.1.22 发布,此版本是个维护版本,现已提供下载,更新内容如下:

新特性

  • docs now have anchor links for easier navigation

  • there is more documentation for things that weren't that clear

  • json-p support added

  • m() now supports splat for children (e.g. m("div", m("a"), m("b"), m("i")) for nicer Coffeescript syntax

  • by popular demand, m.module now returns a controller instance

Bug 修复:

  • gracefully degrade on IE exceptions when setting invalid values

  • fixes for Typescript definition file

  • fixed bug in keys algorithm when mixing keyed and unkeyed elements #246

  • added promise exception monitor and reverted promise exception handling semantics to v0.1.19 semantics (see docs)

  • fixed redraw scheduling bug in old version of IE

  • fixed incorrect diff when document is root, and html element is omitted

  • fixed querystring clobbering in links w/ config:m.route #261

  • fixed rare bug that made events get dropped #214

  • don't send Content-Type header if there's no request data #280


示例:

//namespace  var app = {};    //model  app.PageList = function() {   return m.request({method: "GET", url: "pages.json"});  };    //controller  app.controller = function() {   this.pages = app.PageList();      this.rotate = function() {    this.pages().push(this.pages().shift())   }.bind(this)  };    //view  app.view = function(ctrl) {   return [    ctrl.pages().map(function(page) {     return m("a", {href: page.url}, page.title);    }),    m("a", {onclick: ctrl.rotate}, "Rotate links")   ];  };    //initialize  m.module(document.getElementById("example"), app);

性能比较:

qq截图20140928172305.png