lhorie/mithril.js — pull request #291 by bsuh (2014-10-01 17:52:16+00:00)
Title: Partial rerendering proof of concept

This is a proof of concept and meant to generate discussion rather than be actually pulled.

This adds a `m.submodule` method. The function definition is a bit different from `m.module` in that the first argument is an already instantiated controller object instance instead of a controller constructor function. It also returns a virtual DOM object as it's meant to be used from view functions.

There is also a `m.redraw.target` prop, which can be set to a falsey value to redraw the entire application or an object like `{ node: domNode, controller: controllerInstance, view: viewFunction }` and during the next redraw, Mithril will call `m.render(target.node, target.view(target.controller))`.

During the DOM `build` process, the closest parent module/submodule is kept track of and any event handlers attached will set `m.redraw.target` appropriately.

Here's a modified todo list, which adds a rendered count to each todo, and lists each todo twice. The top todos are rendered with `m.submodule` and the duplicates are rendered normally. You can add a few todos, and then toggle the checkboxes. You can see toggling the first todos only change the render count of the todo, while the duplicate todos rerender the entire application.

http://plnkr.co/edit/eDt6FAqM3NhNam0AqiQU?p=preview