JavaScript 的 MVC 框架,Mithril 0.1.22 發布

jopen 10年前發布 | 7K 次閱讀 Mithril

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

  • </ul>

    示例:

    //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);</pre>

    性能比較:

    qq截圖20140928172305.png

     

     本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
     轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
     本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!