Merge remote-tracking branch 'origin/rewrite' into rewrite

This commit is contained in:
Leo Horie 2017-01-08 08:21:46 -05:00
commit f0d6b0d58b
13 changed files with 437 additions and 65 deletions

View file

@ -34,6 +34,6 @@ There are over 4000 assertions in the test suite, and tests cover even difficult
## Modularity
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.58 KB<!-- /size --> min+gzip
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.60 KB<!-- /size --> min+gzip
In addition, Mithril is now completely modular: you can import only the modules that you need and easily integrate 3rd party modules if you wish to use a different library for routing, ajax, and even rendering

120
docs/autoredraw.md Normal file
View file

@ -0,0 +1,120 @@
# The auto-redraw system
Mithril implements a virtual DOM diffing system for fast rendering, and in addition, it offers various mechanisms to gain granular control over the rendering of an application.
When used idiomatically, Mithril employs an auto-redraw system that synchronizes the DOM whenever changes are made in the data layer. The auto-redraw system becomes enabled when you call `m.mount` or `m.route` (but it stays disabled if your app is bootstrapped solely via `m.render` calls).
The auto-redraw system simply consists of triggering a re-render function behind the scenes after certain functions complete.
### After event handlers
Mithril automatically redraws after DOM event handlers that are defined in a Mithril view:
```javascript
var MyComponent = {
view: function() {
return m("div", {onclick: doSomething})
}
}
function doSomething() {
//a redraw happens synchronously after this function runs
}
m.mount(document.body, MyComponent)
```
You can disable an auto-redraw for specific events by setting `e.redraw` to `false`.
```javascript
var MyComponent = {
view: function() {
return m("div", {onclick: doSomething})
}
}
function doSomething(e) {
e.redraw = false
// no longer triggers a redraw when the div is clicked
}
m.mount(document.body, MyComponent)
```
### After m.request
Mithril automatically redraws after [`m.request`](request.md) completes:
```javascript
m.request("/api/v1/users").then(function() {
//a redraw happens after this function runs
})
```
You can disable an auto-redraw for a specific request by setting the `background` option to true:
```javascript
m.request("/api/v1/users", {background: true}).then(function() {
//does not trigger a redraw
})
```
### After route changes
Mithril automatically redraws after [`m.route.set()`](route.md#routeset) calls (or route changes via links that use [`m.route.link`](route.md#routelink)
```javascript
var RoutedComponent = {
view: function() {
return [
// a redraw happens asynchronously after the route changes
m("a", {href: "/", oncreate: m.route.link}),
m("div", {
onclick: function() {
m.route.set("/")
}
}),
]
}
}
m.route(document.body, "/", {
"/": RoutedComponent,
})
```
---
### When Mithril does not redraws
Mithril does not redraw after 3rd party library event handlers. In those cases, you must manually call [`m.redraw()`](redraw.md).
Mithril also does not redraw after lifecycle methods. This is because lifecycle methods run within the redraw cycle and allowing a nested redraw to run could cause loss of stability or even stack overflows. If you need to trigger a redraw within a lifecycle method, you should call `m.redraw` from within the callback of an asynchronous function such as `requestAnimationFrame`, `Promise.resolve` or `setTimeout`.
```javascript
var StableComponent = {
oncreate: function(vnode) {
vnode.state.height = vnode.dom.offsetHeight
requestAnimationFrame(function() {
m.redraw()
})
},
view: function() {
return m("div", "This component is " + vnode.state.height + "px tall")
}
}
```
Mithril does not auto-redraw vnode trees that are rendered via `m.render`. This means redraws do not occur after event changes and `m.request` calls for templates that were rendered via `m.render`. Thus, if your architecture requires manual control over when rendering occurs (as can sometimes be the case when using libraries like Redux), you should use `m.render` instead of `m.mount`.
Remember that `m.render` expects a vnode tree, and `m.mount` expects a component:
```javascript
// wrap the component in a m() call for m.render
m.render(document.body, m(MyComponent))
// don't wrap the component for m.mount
m.mount(document.body, MyComponent)
```

69
docs/es6.md Normal file
View file

@ -0,0 +1,69 @@
# ES6
Mithril is written in ES5, and is fully compatible with ES6 as well.
In some limited environments, it's possible to use a significant subset of ES6 directly without extra tooling (for example, in internal applications that do not support IE). However, for the vast majority of use cases, a compiler toolchain like [Babel](https://babeljs.io) is required to compile ES6 features down to ES5.
### Setup
The simplest way to setup an ES6 compilation toolchain is via [Babel](https://babeljs.io/). To install, use this command:
```bash
npm install babel-cli babel-preset-es2015 transform-react-jsx --save-dev
```
Create a `.babelrc` file:
```
{
"presets": ["es2015"],
"plugins": [
["transform-react-jsx", {
"pragma": "m"
}]
]
}
```
To run Babel as a standalone tool, run this from the command line:
```bash
babel src --out-dir lib --source-maps
```
#### Using Babel with Webpack
If you're using Webpack as a bundler, you can integrate Babel to Webpack, however this requires some additional dependencies, in addition to the steps above.
```bash
npm install babel-core babel-loader --save-dev
```
Create a file called `.webpack.config`
```javascript
module.exports = {
entry: './src/index.js',
output: {
path: './bin',
filename: 'app.js',
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
}
}
```
---
### Custom setups
If you're using Webpack, you can [follow its excellent guide to add support for ES6](https://webpack.github.io/docs/usage.html#transpiling-es2015-using-babel-loader)
If you want to use Babel as a standalone tool, [here's the instructions for how to set it up](https://babeljs.io/docs/setup/#installation).
[Google closure compiler](https://www.npmjs.com/package/google-closure-compiler) is another tool that supports ES6 to ES5 compilation.

View file

@ -2,6 +2,8 @@
- [Installation](installation.md)
- [Introduction](introduction.md)
- [Tutorial](simple-application.md)
- [JSX](jsx.md)
- [ES6](es6.md)
- [Testing](testing.md)
- [Examples](examples.md)
- Key concepts
@ -9,6 +11,7 @@
- [Components](components.md)
- [Lifecycle methods](lifecycle-methods.md)
- [Keys](keys.md)
- [Autoredraw system](autoredraw.md)
- Social
- [Mithril Jobs](https://github.com/lhorie/mithril.js/wiki/JOBS)
- [How to contribute](contributing.md)

View file

@ -25,7 +25,7 @@ Note: This introduction assumes you have basic level of Javacript knowledge. If
The easiest way to try out Mithril is to include it from a CDN, and follow this tutorial. It'll cover the majority of the API surface (including routing and XHR) but it'll only take 10 minutes.
Let's create an HTML file to follow along:
Let's create an HTML file to follow along:
```markup
<body></body>
@ -91,7 +91,7 @@ m("main", [
])
```
Note: If you prefer `<html>` syntax, [it's possible to use it via a Babel plugin](https://babeljs.io/docs/plugins/transform-react-jsx/).
Note: If you prefer `<html>` syntax, [it's possible to use it via a Babel plugin](jsx.md).
```markup
// HTML syntax via Babel's JSX plugin
@ -236,8 +236,3 @@ Clicking the button should now update the count.
We covered how to create and update HTML, how to create components, routes for a Single Page Application, and interacted with a server via XHR.
This should be enough to get you started writing the frontend for a real application. Now that you are comfortable with the basics of the Mithril API, [be sure to check out the simple application tutorial](simple-application.md), which walks you through building a realistic application.

177
docs/jsx.md Normal file
View file

@ -0,0 +1,177 @@
# JSX
- [Description](#description)
- [Setup](#setup)
- [JSX vs hyperscript](#jsx-vs-hyperscript)
- [Converting HTML](#converting-html)
---
### Description
JSX is a syntax extension that enables you to write HTML tags interspersed with Javascript.
```
var MyComponent = {
view: function() {
return m("main", [
m("h1", "Hello world"),
])
}
}
// can be written as:
var MyComponent = {
view: function() {
return (
<main>
<h1>Hello world</h1>
</main>
)
}
}
```
When using JSX, it's possible to interpolate Javascript expressions within JSX tags by using curly braces:
```
var greeting = "Hello"
var url = "http://google.com"
var div = <a href={url}>{greeting + "!"}</a>
```
Components can be used by using a convention of uppercasing the first letter of the component name:
```javascript
m.mount(document.body, <MyComponent />)
// equivalent to m.mount(document.body, m(MyComponent))
```
---
### Setup
The simplest way to use JSX is via a [Babel](https://babeljs.io/) plugin. To install, use this command:
```bash
npm install babel-cli babel-preset-es2015 transform-react-jsx --save-dev
```
Create a `.babelrc` file:
```
{
"presets": ["es2015"],
"plugins": [
["transform-react-jsx", {
"pragma": "m"
}]
]
}
```
To run Babel as a standalone tool, run this from the command line:
```bash
babel src --out-dir lib --source-maps
```
#### Using Babel with Webpack
If you're using Webpack as a bundler, you can integrate Babel to Webpack, however this requires some additional dependencies, in addition to the steps above.
```bash
npm install babel-core babel-loader --save-dev
```
Create a file called `.webpack.config`
```javascript
module.exports = {
entry: './src/index.js',
output: {
path: './bin',
filename: 'app.js',
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
}
}
```
---
### JSX vs hyperscript
JSX is essentially a trade-off: it introduces a non-standard syntax that cannot be run without appropriate tooling, in order to allow a developer to write HTML code using curly braces. The main benefit of using JSX instead of regular HTML is that the JSX specification is much stricter and yields syntax errors when appropriate, whereas HTML is far too forgiving and makes syntax issues difficult to spot.
Unlike HTML, JSX is case-sensitive. This means `<div className="test"></div>` is different from `<div classname="test"></div>` (all lower case). The former compiles to `m("div", {className: "test"})` and the latter compiles to `m("div", {classname: "test"})`, which is not a valid way of creating a class attribute). Fortunately, Mithril supports standard HTML attribute names, and thus, this example can be written like regular HTML: `<div class="test"></div>`.
JSX is useful for teams where HTML is primarily written by someone without Javascript experience, but it requires a significant amount of tooling to maintain (whereas plain HTML can, for the most part, simply be opened in a browser)
Hyperscript is the compiled representation of JSX. It's designed to be readable and can also be used as-is, instead of JSX (as is done in most of the documentation). Hyperscript tends to be terser than JSX for a couple of reasons:
1 - it does not require repeating the tag name in closing tags (e.g. `m("div")` vs `<div></div>`)
2 - static attributes can be written using CSS selector syntax (i.e. `m("a.button")` vs `<div class="button"></div>`
In addition, since hyperscript is plain Javascript, it's often more natural to indent than JSX:
```
//JSX
var BigComponent = {
activate: function() {/*...*/},
deactivate: function() {/*...*/},
update: function() {/*...*/},
view: function(vnode) {
return [
{vnode.attrs.items.map(function(item) {
return <div>{item.name}</div>
})}
<div
ondragover={this.activate}
ondragleave={this.deactivate}
ondragend={this.deactivate}
ondrop={this.update}
onblur={this.deactivate}
></div>
]
}
}
// hyperscript
var BigComponent = {
activate: function() {/*...*/},
deactivate: function() {/*...*/},
update: function() {/*...*/},
view: function(vnode) {
return [
vnode.attrs.items.map(function(item) {
return m("div", item.name)
}),
m("div", {
ondragover: this.activate,
ondragleave: this.deactivate,
ondragend: this.deactivate,
ondrop: this.update,
onblur: this.deactivate,
})
]
}
}
```
In non-trivial applications, it's possible for components to have more control flow and component configuration code than markup, making a Javascript-first approach more readable than an HTML-first approach.
Needless to say, since hyperscript is pure Javascript, there's no need to run a compilation step to produce runnable code.
---
### Converting HTML
In Mithril, well-formed HTML is valid JSX. Little effort other than copy-pasting is required to integrate an independently produced HTML file into a project using JSX.
When using hyperscript, it's necessary to convert HTML to hyperscript syntax before the code can be run. To facilitate this, you can [use the HTML-to-Mithril-template converter](http://arthurclemens.github.io/mithril-template-converter/index.html).

View file

@ -5,7 +5,7 @@ function Vnode(tag, key, attrs0, children, text, dom) {
}
Vnode.normalize = function(node) {
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node, undefined, undefined)
if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node === false ? "" : node, undefined, undefined)
return node
}
Vnode.normalizeChildren = function normalizeChildren(children) {
@ -430,11 +430,7 @@ var coreRenderer = function($window) {
return element
}
function createComponent(vnode, hooks, ns) {
// For object literals since `Vnode()` always sets the `state` field.
if (!vnode.state) vnode.state = {}
var constructor = function() {}
constructor.prototype = vnode.tag
vnode.state = new constructor
vnode.state = Object.create(vnode.tag)
var view = vnode.tag.view
if (view.reentrantLock != null) return $emptyFragment
view.reentrantLock = true

84
mithril.min.js vendored
View file

@ -1,42 +1,42 @@
new function(){function w(b,c,h,d,g,l){return{tag:b,key:c,attrs:h,children:d,text:g,dom:l,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(b){if(null==b||"string"!==typeof b&&null==b.view)throw Error("The selector must be either a string or a component.");if("string"===typeof b&&void 0===G[b]){for(var c,h,d=[],g={};c=N.exec(b);){var l=c[1],m=c[2];""===l&&""!==m?h=m:"#"===l?g.id=m:"."===l?d.push(m):"["===c[3][0]&&((l=c[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
"class"===c[4]?d.push(l):g[c[4]]=l||!0)}0<d.length&&(g.className=d.join(" "));G[b]=function(b,c){var d=!1,a,l,n=b.className||b["class"],z;for(z in g)b[z]=g[z];void 0!==n&&(void 0!==b["class"]&&(b["class"]=void 0,b.className=n),void 0!==g.className&&(b.className=g.className+" "+n));for(z in b)if("key"!==z){d=!0;break}Array.isArray(c)&&1==c.length&&null!=c[0]&&"#"===c[0].tag?l=c[0].children:a=c;return w(h||"div",b.key,d?b:void 0,a,l,void 0)}}var q;null==arguments[1]||"object"===typeof arguments[1]&&
void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(q=arguments[1],d=2):d=1;if(arguments.length===d+1)c=Array.isArray(arguments[d])?arguments[d]:[arguments[d]];else for(c=[];d<arguments.length;d++)c.push(arguments[d]);return"string"===typeof b?G[b](q||{},w.normalizeChildren(c)):w(b,q&&q.key,q||{},w.normalizeChildren(c),void 0,void 0)}function O(b){var c=0,h=null,d="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var g=Date.now();0===c||16<=g-c?(c=g,
b()):null===h&&(h=d(function(){h=null;b();c=Date.now()},16-(g-c)))}}w.normalize=function(b){return Array.isArray(b)?w("[",void 0,void 0,w.normalizeChildren(b),void 0,void 0):null!=b&&"object"!==typeof b?w("#",void 0,void 0,b,void 0,void 0):b};w.normalizeChildren=function(b){for(var c=0;c<b.length;c++)b[c]=w.normalize(b[c]);return b};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};A.trust=function(b){null==b&&(b="");return w("<",void 0,void 0,b,void 0,void 0)};
A.fragment=function(b,c){return w("[",b.key,b,w.normalizeChildren(c),void 0,void 0)};var x=function(b){function c(b,a){return function p(c){var m;try{if(!a||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(m=c.then))k(function(){a||0!==b.length||console.error("Possible unhandled promise rejection:",c);for(var d=0;d<b.length;d++)b[d](c);g.length=0;l.length=0;n.state=a;n.retry=function(){p(c)}});else{if(c===d)throw new TypeError("Promise can't be resolved w/ itself");h(m.bind(c))}}catch(P){q(P)}}}
function h(b){function a(a){return function(b){0<c++||a(b)}}var c=0,d=a(q);try{b(a(m),d)}catch(z){d(z)}}if(!(this instanceof x))throw Error("Promise must be called with `new`");if("function"!==typeof b)throw new TypeError("executor must be a function");var d=this,g=[],l=[],m=c(g,!0),q=c(l,!1),n=d._instance={resolvers:g,rejectors:l},k="function"===typeof setImmediate?setImmediate:setTimeout;h(b)};x.prototype.then=function(b,c){function h(b,c,h,m){c.push(function(a){if("function"!==typeof b)h(a);else try{g(b(a))}catch(C){l&&
l(C)}});"function"===typeof d.retry&&m===d.state&&d.retry()}var d=this._instance,g,l,m=new x(function(b,c){g=b;l=c});h(b,d.resolvers,g,!0);h(c,d.rejectors,l,!1);return m};x.prototype["catch"]=function(b){return this.then(null,b)};x.resolve=function(b){return b instanceof x?b:new x(function(c){c(b)})};x.reject=function(b){return new x(function(c,h){h(b)})};x.all=function(b){return new x(function(c,h){var d=b.length,g=0,l=[];if(0===b.length)c([]);else for(var m=0;m<b.length;m++)(function(m){function n(b){g++;
l[m]=b;g===d&&c(l)}null==b[m]||"object"!==typeof b[m]&&"function"!==typeof b[m]||"function"!==typeof b[m].then?n(b[m]):b[m].then(n,h)})(m)})};x.race=function(b){return new x(function(c,h){for(var d=0;d<b.length;d++)b[d].then(c,h)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=x),x=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=x),x=global.Promise);var D=function(b){function c(b,d){if(Array.isArray(d))for(var g=
0;g<d.length;g++)c(b+"["+g+"]",d[g]);else if("[object Object]"===Object.prototype.toString.call(d))for(g in d)c(b+"["+g+"]",d[g]);else h.push(encodeURIComponent(b)+(null!=d&&""!==d?"="+encodeURIComponent(d):""))}if("[object Object]"!==Object.prototype.toString.call(b))return"";var h=[],d;for(d in b)c(d,b[d]);return h.join("&")},I=function(b,c){function h(){function a(){0===--b&&"function"===typeof t&&t()}var b=0;return function z(c){var d=c.then;c.then=function(){b++;var g=d.apply(c,arguments);g.then(a,
function(c){a();if(0===b)throw c;});return z(g)};return c}}function d(a,b){if("string"===typeof a){var c=a;a=b||{};null==a.url&&(a.url=c)}return a}function g(a,b){if(null==b)return a;for(var c=a.match(/:[^\/]+/gi)||[],d=0;d<c.length;d++){var g=c[d].slice(1);null!=b[g]&&(a=a.replace(c[d],b[g]),delete b[g])}return a}function l(a,b){var c=D(b);if(""!==c){var d=0>a.indexOf("?")?"?":"&";a+=d+c}return a}function m(b){try{return""!==b?JSON.parse(b):null}catch(C){throw Error(b);}}function q(b){return b.responseText}
function n(b,c){if("function"===typeof b)if(Array.isArray(c))for(var a=0;a<c.length;a++)c[a]=new b(c[a]);else return new b(c);return c}var k=0,t;return{request:function(a,k){var t=h();a=d(a,k);var z=new c(function(c,d){null==a.method&&(a.method="GET");a.method=a.method.toUpperCase();var h="boolean"===typeof a.useBody?a.useBody:"GET"!==a.method&&"TRACE"!==a.method;"function"!==typeof a.serialize&&(a.serialize="undefined"!==typeof FormData&&a.data instanceof FormData?function(b){return b}:JSON.stringify);
"function"!==typeof a.deserialize&&(a.deserialize=m);"function"!==typeof a.extract&&(a.extract=q);a.url=g(a.url,a.data);h?a.data=a.serialize(a.data):a.url=l(a.url,a.data);var k=new b.XMLHttpRequest;k.open(a.method,a.url,"boolean"===typeof a.async?a.async:!0,"string"===typeof a.user?a.user:void 0,"string"===typeof a.password?a.password:void 0);a.serialize===JSON.stringify&&h&&k.setRequestHeader("Content-Type","application/json; charset=utf-8");a.deserialize===m&&k.setRequestHeader("Accept","application/json, text/*");
a.withCredentials&&(k.withCredentials=a.withCredentials);for(var t in a.headers)({}).hasOwnProperty.call(a.headers,t)&&k.setRequestHeader(t,a.headers[t]);"function"===typeof a.config&&(k=a.config(k,a)||k);k.onreadystatechange=function(){if(4===k.readyState)try{var b=a.extract!==q?a.extract(k,a):a.deserialize(a.extract(k,a));if(200<=k.status&&300>k.status||304===k.status)c(n(a.type,b));else{var g=Error(k.responseText),e;for(e in b)g[e]=b[e];d(g)}}catch(f){d(f)}};h&&null!=a.data?k.send(a.data):k.send()});
return!0===a.background?z:t(z)},jsonp:function(a,m){var t=h();a=d(a,m);var q=new c(function(c,d){var h=a.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+k++,m=b.document.createElement("script");b[h]=function(d){m.parentNode.removeChild(m);c(n(a.type,d));delete b[h]};m.onerror=function(){m.parentNode.removeChild(m);d(Error("JSONP request failed"));delete b[h]};null==a.data&&(a.data={});a.url=g(a.url,a.data);a.data[a.callbackKey||"callback"]=h;m.src=l(a.url,a.data);b.document.documentElement.appendChild(m)});
return!0===a.background?q:t(q)},setCompletionCallback:function(b){t=b}}}(window,x),M=function(b){function c(e,f,b,a,c,d,g){for(;b<a;b++){var r=f[b];null!=r&&k(e,h(r,c,g),d)}}function h(e,f,b){var a=e.tag;null!=e.attrs&&H(e.attrs,e,f);if("string"===typeof a)switch(a){case "#":return e.dom=B.createTextNode(e.children);case "<":return d(e);case "[":var r=B.createDocumentFragment();null!=e.children&&(a=e.children,c(r,a,0,a.length,f,null,b));e.dom=r.firstChild;e.domSize=r.childNodes.length;return r;default:var h=
e.tag;switch(e.tag){case "svg":b="http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}var k=(a=e.attrs)&&a.is,h=b?k?B.createElementNS(b,h,{is:k}):B.createElementNS(b,h):k?B.createElement(h,{is:k}):B.createElement(h);e.dom=h;if(null!=a)for(r in k=b,a)z(e,r,null,a[r],k);null!=e.attrs&&null!=e.attrs.contenteditable?t(e):(null!=e.text&&(""!==e.text?h.textContent=e.text:e.children=[w("#",void 0,void 0,e.text,void 0,void 0)]),null!=e.children&&(r=e.children,c(h,r,0,r.length,
f,null,b),f=e.attrs,"select"===e.tag&&null!=f&&("value"in f&&z(e,"value",null,f.value,void 0),"selectedIndex"in f&&z(e,"selectedIndex",null,f.selectedIndex,void 0))));return h}else return g(e,f,b)}function d(e){var f={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(e.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",f=B.createElement(f);f.innerHTML=e.children;e.dom=f.firstChild;e.domSize=f.childNodes.length;e=B.createDocumentFragment();
for(var b;b=f.firstChild;)e.appendChild(b);return e}function g(e,f,b){e.state||(e.state={});var a=function(){};a.prototype=e.tag;e.state=new a;a=e.tag.view;if(null!=a.reentrantLock)return L;a.reentrantLock=!0;H(e.tag,e,f);e.instance=w.normalize(a.call(e.state,e));a.reentrantLock=null;if(null!=e.instance){if(e.instance===e)throw Error("A view cannot return the vnode it received as arguments");f=h(e.instance,f,b);e.dom=e.instance.dom;e.domSize=null!=e.dom?e.instance.domSize:0;return f}e.domSize=0;return L}
function l(e,f,b,d,g,l){if(f!==b&&(null!=f||null!=b))if(null==f)c(e,b,0,b.length,d,g,void 0);else if(null==b)a(f,0,f.length,b);else{if(f.length===b.length){for(var r=!1,u=0;u<b.length;u++)if(null!=b[u]&&null!=f[u]){r=null==b[u].key&&null==f[u].key;break}if(r){for(u=0;u<f.length;u++)f[u]!==b[u]&&(null==f[u]&&null!=b[u]?k(e,h(b[u],d,l),n(f,u+1,g)):null==b[u]?a(f,u,u+1,b):m(e,f[u],b[u],d,n(f,u+1,g),!1,l));return}}a:{if(null!=f.pool&&Math.abs(f.pool.length-b.length)<=Math.abs(f.length-b.length)&&(r=b[0]&&
b[0].children&&b[0].children.length||0,Math.abs((f.pool[0]&&f.pool[0].children&&f.pool[0].children.length||0)-r)<=Math.abs((f[0]&&f[0].children&&f[0].children.length||0)-r))){r=!0;break a}r=!1}r&&(f=f.concat(f.pool));for(var t=u=0,v=f.length-1,z=b.length-1,C;v>=u&&z>=t;){var y=f[u],p=b[t];if(y!==p||r)if(null==y)u++;else if(null==p)t++;else if(y.key===p.key)u++,t++,m(e,y,p,d,n(f,u,g),r,l),r&&y.tag===p.tag&&k(e,q(y),g);else if(y=f[v],y!==p||r)if(null==y)v--;else if(null==p)t++;else if(y.key===p.key)m(e,
y,p,d,n(f,v+1,g),r,l),(r||t<z)&&k(e,q(y),n(f,u,g)),v--,t++;else break;else v--,t++;else u++,t++}for(;v>=u&&z>=t;){y=f[v];p=b[z];if(y!==p||r)if(null==y)v--;else{if(null!=p)if(y.key===p.key)m(e,y,p,d,n(f,v+1,g),r,l),r&&y.tag===p.tag&&k(e,q(y),g),null!=y.dom&&(g=y.dom),v--;else{if(!C){C=f;var y=v,E={},w;for(w=0;w<y;w++){var x=C[w];null!=x&&(x=x.key,null!=x&&(E[x]=w))}C=E}null!=p&&(y=C[p.key],null!=y?(E=f[y],m(e,E,p,d,n(f,v+1,g),r,l),k(e,q(E),g),f[y].skip=!0,null!=E.dom&&(g=E.dom)):(p=h(p,d,void 0),k(e,
p,g),g=p))}z--}else v--,z--;if(z<t)break}c(e,b,t,z+1,d,g,l);a(f,u,v+1,b)}}function m(b,f,a,c,g,n,p){var e=f.tag;if(e===a.tag){a.state=f.state;a.events=f.events;var r;var u;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&(r=a.attrs.onbeforeupdate.call(a.state,a,f));"string"!==typeof a.tag&&"function"===typeof a.tag.onbeforeupdate&&(u=a.tag.onbeforeupdate.call(a.state,a,f));void 0===r&&void 0===u||r||u?r=!1:(a.dom=f.dom,a.domSize=f.domSize,a.instance=f.instance,r=!0);if(!r)if(null!=a.attrs&&
K(a.attrs,a,c,n),"string"===typeof e)switch(e){case "#":f.children.toString()!==a.children.toString()&&(f.dom.nodeValue=a.children);a.dom=f.dom;break;case "<":f.children!==a.children?(q(f),k(b,d(a),g)):(a.dom=f.dom,a.domSize=f.domSize);break;case "[":l(b,f.children,a.children,c,g,p);f=0;c=a.children;a.dom=null;if(null!=c){for(var v=0;v<c.length;v++)b=c[v],null!=b&&null!=b.dom&&(null==a.dom&&(a.dom=b.dom),f+=b.domSize||1);1!==f&&(a.domSize=f)}break;default:b=p;g=a.dom=f.dom;switch(a.tag){case "svg":b=
"http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}"textarea"===a.tag&&(null==a.attrs&&(a.attrs={}),null!=a.text&&(a.attrs.value=a.text,a.text=void 0));n=f.attrs;p=a.attrs;e=b;if(null!=p)for(v in p)z(a,v,n&&n[v],p[v],e);if(null!=n)for(v in n)null!=p&&v in p||("className"===v&&(v="class"),"o"!==v[0]||"n"!==v[1]||x(v)?"key"!==v&&a.dom.removeAttribute(v):A(a,v,void 0));null!=a.attrs&&null!=a.attrs.contenteditable?t(a):null!=f.text&&null!=a.text&&""!==a.text?f.text.toString()!==
a.text.toString()&&(f.dom.firstChild.nodeValue=a.text):(null!=f.text&&(f.children=[w("#",void 0,void 0,f.text,void 0,f.dom.firstChild)]),null!=a.text&&(a.children=[w("#",void 0,void 0,a.text,void 0,void 0)]),l(g,f.children,a.children,c,null,b))}else a.instance=w.normalize(a.tag.view.call(a.state,a)),K(a.tag,a,c,n),null!=a.instance?(null==f.instance?k(b,h(a.instance,c,p),g):m(b,f.instance,a.instance,c,g,n,p),a.dom=a.instance.dom,a.domSize=a.instance.domSize):null!=f.instance?(C(f.instance,null),a.dom=
void 0,a.domSize=0):(a.dom=f.dom,a.domSize=f.domSize)}else C(f,null),k(b,h(a,c,p),g)}function q(a){var b=a.domSize;if(null!=b||null==a.dom){var e=B.createDocumentFragment();if(0<b){for(a=a.dom;--b;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function n(a,b,c){for(;b<a.length;b++)if(null!=a[b]&&null!=a[b].dom)return a[b].dom;return c}function k(a,b,c){c&&c.parentNode?a.insertBefore(b,c):a.appendChild(b)}function t(a){var b=a.children;if(null!=b&&1===b.length&&
"<"===b[0].tag)b=b[0].children,a.dom.innerHTML!==b&&(a.dom.innerHTML=b);else if(null!=a.text||null!=b&&0!==b.length)throw Error("Child node of a contenteditable must be trusted");}function a(a,b,c,d){for(;b<c;b++){var e=a[b];null!=e&&(e.skip?e.skip=!1:C(e,d))}}function C(a,b){function e(){if(++c===f&&(p(a),a.dom)){var e=a.domSize||1;if(1<e)for(var d=a.dom;--e;){var g=d.nextSibling,h=g.parentNode;null!=h&&h.removeChild(g)}e=a.dom;d=e.parentNode;null!=d&&d.removeChild(e);if(e=null!=b&&null==a.domSize)e=
a.attrs,e=!(null!=e&&(e.oncreate||e.onupdate||e.onbeforeremove||e.onremove));e&&"string"===typeof a.tag&&(b.pool?b.pool.push(a):b.pool=[a])}}var f=1,c=0;if(a.attrs&&a.attrs.onbeforeremove){var d=a.attrs.onbeforeremove.call(a.state,a);null!=d&&"function"===typeof d.then&&(f++,d.then(e,e))}"string"!==typeof a.tag&&a.tag.onbeforeremove&&(d=a.tag.onbeforeremove.call(a.state,a),null!=d&&"function"===typeof d.then&&(f++,d.then(e,e)));e()}function p(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,
a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)p(a.instance);else if(a=a.children,Array.isArray(a))for(var b=0;b<a.length;b++){var e=a[b];null!=e&&p(e)}}function z(a,b,c,d,g){var e=a.dom;if("key"!==b&&"is"!==b&&(c!==d||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===B.activeElement||"object"===typeof d)&&"undefined"!==typeof d&&!x(b)){var f=b.indexOf(":");if(-1<f&&"xlink"===b.substr(0,f))e.setAttributeNS("http://www.w3.org/1999/xlink",
b.slice(f+1),d);else if("o"===b[0]&&"n"===b[1]&&"function"===typeof d)A(a,b,d);else if("style"===b)if(a=c,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var h in d)e.style[h]=d[h];if(null!=a&&"string"!==typeof a)for(h in a)h in d||(e.style[h]="")}else b in e&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===g&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&
"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"select"===a.tag&&"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"option"===a.tag&&"value"===b&&a.dom.value===d||(e[b]=d):"boolean"===typeof d?d?e.setAttribute(b,""):e.removeAttribute(b):e.setAttribute("className"===b?"class":b,d)}}function x(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function A(a,b,c){var e=a.dom,d="function"!==typeof D?c:function(a){var b=c.call(e,
a);D.call(e,a);return b};if(b in e)e[b]="function"===typeof c?d:null;else{var f=b.slice(2);void 0===a.events&&(a.events={});a.events[b]!==d&&(null!=a.events[b]&&e.removeEventListener(f,a.events[b],!1),"function"===typeof c&&(a.events[b]=d,e.addEventListener(f,a.events[b],!1)))}}function H(a,b,c){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&c.push(a.oncreate.bind(b.state,b))}function K(a,b,c,d){d?H(a,b,c):"function"===typeof a.onupdate&&c.push(a.onupdate.bind(b.state,
b))}var B=b.document,L=B.createDocumentFragment(),D;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);l(a,a.vnodes,w.normalizeChildren(b),c,null,void 0);a.vnodes=b;for(var e=0;e<c.length;e++)c[e]();B.activeElement!==d&&d.focus()},setEventCallback:function(a){return D=a}}},F=function(b){function c(b){b=d.indexOf(b);-1<b&&d.splice(b,
2)}function h(){for(var b=1;b<d.length;b+=2)d[b]()}b=M(b);b.setEventCallback(function(b){!1!==b.redraw&&h()});var d=[];return{subscribe:function(b,h){c(b);d.push(b,O(h))},unsubscribe:c,redraw:h,render:b.render}}(window);I.setCompletionCallback(F.redraw);A.mount=function(b){return function(c,h){if(null===h)b.render(c,[]),b.unsubscribe(c);else{if(null==h.view)throw Error("m.mount(element, component) expects a component, not a vnode");b.subscribe(c,function(){b.render(c,w(h))});b.redraw()}}}(F);var Q=
x,J=function(b){if(""===b||null==b)return{};"?"===b.charAt(0)&&(b=b.slice(1));b=b.split("&");for(var c={},h={},d=0;d<b.length;d++){var g=b[d].split("="),l=decodeURIComponent(g[0]),g=2===g.length?decodeURIComponent(g[1]):"";"true"===g?g=!0:"false"===g&&(g=!1);var m=l.split(/\]\[?|\[/),q=c;-1<l.indexOf("[")&&m.pop();for(var n=0;n<m.length;n++){var l=m[n],k=m[n+1],k=""==k||!isNaN(parseInt(k,10)),t=n===m.length-1;""===l&&(l=m.slice(0,n).join(),null==h[l]&&(h[l]=0),l=h[l]++);null==q[l]&&(q[l]=t?g:k?[]:
{});q=q[l]}}return c},R=function(b){function c(c){var d=b.location[c].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===c&&"/"!==d[0]&&(d="/"+d);return d}function h(b){return function(){null==m&&(m=l(function(){m=null;b()}))}}function d(b,c,d){var a=b.indexOf("?"),g=b.indexOf("#"),h=-1<a?a:-1<g?g:b.length;if(-1<a){var a=J(b.slice(a+1,-1<g?g:b.length)),k;for(k in a)c[k]=a[k]}if(-1<g)for(k in c=J(b.slice(g+1)),c)d[k]=c[k];return b.slice(0,h)}var g="function"===typeof b.history.pushState,
l="function"===typeof setImmediate?setImmediate:setTimeout,m,q={prefix:"#!",getPath:function(){switch(q.prefix.charAt(0)){case "#":return c("hash").slice(q.prefix.length);case "?":return c("search").slice(q.prefix.length)+c("hash");default:return c("pathname").slice(q.prefix.length)+c("search")+c("hash")}},setPath:function(c,h,m){var a={},k={};c=d(c,a,k);if(null!=h){for(var l in h)a[l]=h[l];c=c.replace(/:([^\/]+)/g,function(b,c){delete a[c];return h[c]})}(l=D(a))&&(c+="?"+l);(k=D(k))&&(c+="#"+k);
g?(k=m?m.state:null,l=m?m.title:null,b.onpopstate(),m&&m.replace?b.history.replaceState(k,l,q.prefix+c):b.history.pushState(k,l,q.prefix+c)):b.location.href=q.prefix+c},defineRoutes:function(c,k,m){function a(){var a=q.getPath(),g={},h=d(a,g,g),l=b.history.state;if(null!=l)for(var t in l)g[t]=l[t];for(var n in c)if(l=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),l.test(h)){h.replace(l,function(){for(var b=n.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,
1,-2),h=0;h<b.length;h++)g[b[h].replace(/:|\./g,"")]=decodeURIComponent(d[h]);k(c[n],g,a,n)});return}m(a,g)}g?b.onpopstate=h(a):"#"===q.prefix.charAt(0)&&(b.onhashchange=a);a()}};return q};A.route=function(b,c){var h=R(b),d=function(b){return b},g,l,m,q,n,k=function(b,a,k){if(null==b)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var p=function(){null!=g&&c.render(b,g(w(l,m.key,m)))},t=function(){h.setPath(a,null,{replace:!0})};h.defineRoutes(k,function(a,b,c){var h=
n=function(a,k){h===n&&(l=null!=k&&"function"===typeof k.view?k:"div",m=b,q=c,n=null,g=(a.render||d).bind(a),p())};a.view?h({},a):a.onmatch?Q.resolve(a.onmatch(b,c)).then(function(b){h(a,b)},t):h(a,"div")},t);c.subscribe(b,p)};k.set=function(b,a,c){null!=n&&(c={replace:!0});n=null;h.setPath(b,a,c)};k.get=function(){return q};k.prefix=function(b){h.prefix=b};k.link=function(b){b.dom.setAttribute("href",h.prefix+b.attrs.href);b.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||
(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(h.prefix)&&(a=a.slice(h.prefix.length)),k.set(a,void 0,void 0))}};return k}(window,F);A.withAttr=function(b,c,h){return function(d){return c.call(h||this,b in d.currentTarget?d.currentTarget[b]:d.currentTarget.getAttribute(b))}};var S=M(window);A.render=S.render;A.redraw=F.redraw;A.request=I.request;A.jsonp=I.jsonp;A.parseQueryString=J;A.buildQueryString=D;A.version="1.0.0-rc.7";A.vnode=w;"undefined"!==typeof module?module.exports=
A:window.m=A};
new function(){function w(a,c,k,d,h,m){return{tag:a,key:c,attrs:k,children:d,text:h,dom:m,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function B(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===G[a]){for(var c,k,d=[],h={};c=N.exec(a);){var m=c[1],q=c[2];""===m&&""!==q?k=q:"#"===m?h.id=q:"."===m?d.push(q):"["===c[3][0]&&((m=c[6])&&(m=m.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
"class"===c[4]?d.push(m):h[c[4]]=m||!0)}0<d.length&&(h.className=d.join(" "));G[a]=function(a,c){var m=!1,b,t,d=a.className||a["class"],l;for(l in h)a[l]=h[l];void 0!==d&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=d),void 0!==h.className&&(a.className=h.className+" "+d));for(l in a)if("key"!==l){m=!0;break}Array.isArray(c)&&1==c.length&&null!=c[0]&&"#"===c[0].tag?t=c[0].children:b=c;return w(k||"div",a.key,m?a:void 0,b,t,void 0)}}var l;null==arguments[1]||"object"===typeof arguments[1]&&
void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(l=arguments[1],d=2):d=1;if(arguments.length===d+1)c=Array.isArray(arguments[d])?arguments[d]:[arguments[d]];else for(c=[];d<arguments.length;d++)c.push(arguments[d]);return"string"===typeof a?G[a](l||{},w.normalizeChildren(c)):w(a,l&&l.key,l||{},w.normalizeChildren(c),void 0,void 0)}function O(a){var c=0,k=null,d="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var h=Date.now();0===c||16<=h-c?(c=h,
a()):null===k&&(k=d(function(){k=null;a();c=Date.now()},16-(h-c)))}}w.normalize=function(a){return Array.isArray(a)?w("[",void 0,void 0,w.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?w("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};w.normalizeChildren=function(a){for(var c=0;c<a.length;c++)a[c]=w.normalize(a[c]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};B.trust=function(a){null==a&&(a="");return w("<",void 0,void 0,a,void 0,
void 0)};B.fragment=function(a,c){return w("[",a.key,a,w.normalizeChildren(c),void 0,void 0)};var x=function(a){function c(a,b){return function v(c){var q;try{if(!b||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(q=c.then))p(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",c);for(var d=0;d<a.length;d++)a[d](c);h.length=0;m.length=0;t.state=b;t.retry=function(){v(c)}});else{if(c===d)throw new TypeError("Promise can't be resolved w/ itself");
k(q.bind(c))}}catch(P){l(P)}}}function k(a){function b(b){return function(a){0<c++||b(a)}}var c=0,d=b(l);try{a(b(q),d)}catch(D){d(D)}}if(!(this instanceof x))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var d=this,h=[],m=[],q=c(h,!0),l=c(m,!1),t=d._instance={resolvers:h,rejectors:m},p="function"===typeof setImmediate?setImmediate:setTimeout;k(a)};x.prototype.then=function(a,c){function k(a,c,k,q){c.push(function(b){if("function"!==
typeof a)k(b);else try{h(a(b))}catch(r){m&&m(r)}});"function"===typeof d.retry&&q===d.state&&d.retry()}var d=this._instance,h,m,q=new x(function(a,c){h=a;m=c});k(a,d.resolvers,h,!0);k(c,d.rejectors,m,!1);return q};x.prototype["catch"]=function(a){return this.then(null,a)};x.resolve=function(a){return a instanceof x?a:new x(function(c){c(a)})};x.reject=function(a){return new x(function(c,k){k(a)})};x.all=function(a){return new x(function(c,k){var d=a.length,h=0,m=[];if(0===a.length)c([]);else for(var q=
0;q<a.length;q++)(function(l){function t(a){h++;m[l]=a;h===d&&c(m)}null==a[l]||"object"!==typeof a[l]&&"function"!==typeof a[l]||"function"!==typeof a[l].then?t(a[l]):a[l].then(t,k)})(q)})};x.race=function(a){return new x(function(c,k){for(var d=0;d<a.length;d++)a[d].then(c,k)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=x),x=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=x),x=global.Promise);var E=function(a){function c(a,
d){if(Array.isArray(d))for(var h=0;h<d.length;h++)c(a+"["+h+"]",d[h]);else if("[object Object]"===Object.prototype.toString.call(d))for(h in d)c(a+"["+h+"]",d[h]);else k.push(encodeURIComponent(a)+(null!=d&&""!==d?"="+encodeURIComponent(d):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var k=[],d;for(d in a)c(d,a[d]);return k.join("&")},I=function(a,c){function k(){function b(){0===--a&&"function"===typeof z&&z()}var a=0;return function D(c){var d=c.then;c.then=function(){a++;
var h=d.apply(c,arguments);h.then(b,function(c){b();if(0===a)throw c;});return D(h)};return c}}function d(b,a){if("string"===typeof b){var c=b;b=a||{};null==b.url&&(b.url=c)}return b}function h(b,a){if(null==a)return b;for(var c=b.match(/:[^\/]+/gi)||[],d=0;d<c.length;d++){var h=c[d].slice(1);null!=a[h]&&(b=b.replace(c[d],a[h]),delete a[h])}return b}function m(b,a){var c=E(a);if(""!==c){var d=0>b.indexOf("?")?"?":"&";b+=d+c}return b}function q(a){try{return""!==a?JSON.parse(a):null}catch(r){throw Error(a);
}}function l(a){return a.responseText}function t(a,c){if("function"===typeof a)if(Array.isArray(c))for(var b=0;b<c.length;b++)c[b]=new a(c[b]);else return new a(c);return c}var p=0,z;return{request:function(b,p){var z=k();b=d(b,p);var r=new c(function(c,d){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var k="boolean"===typeof b.useBody?b.useBody:"GET"!==b.method&&"TRACE"!==b.method;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?
function(a){return a}:JSON.stringify);"function"!==typeof b.deserialize&&(b.deserialize=q);"function"!==typeof b.extract&&(b.extract=l);b.url=h(b.url,b.data);k?b.data=b.serialize(b.data):b.url=m(b.url,b.data);var n=new a.XMLHttpRequest;n.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize===JSON.stringify&&k&&n.setRequestHeader("Content-Type","application/json; charset=utf-8");b.deserialize===
q&&n.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(n.withCredentials=b.withCredentials);for(var p in b.headers)({}).hasOwnProperty.call(b.headers,p)&&n.setRequestHeader(p,b.headers[p]);"function"===typeof b.config&&(n=b.config(n,b)||n);n.onreadystatechange=function(){if(4===n.readyState)try{var a=b.extract!==l?b.extract(n,b):b.deserialize(b.extract(n,b));if(200<=n.status&&300>n.status||304===n.status)c(t(b.type,a));else{var g=Error(n.responseText),e;for(e in a)g[e]=a[e];
d(g)}}catch(f){d(f)}};k&&null!=b.data?n.send(b.data):n.send()});return!0===b.background?r:z(r)},jsonp:function(b,l){var q=k();b=d(b,l);var z=new c(function(c,d){var k=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+p++,l=a.document.createElement("script");a[k]=function(d){l.parentNode.removeChild(l);c(t(b.type,d));delete a[k]};l.onerror=function(){l.parentNode.removeChild(l);d(Error("JSONP request failed"));delete a[k]};null==b.data&&(b.data={});b.url=h(b.url,b.data);b.data[b.callbackKey||
"callback"]=k;l.src=m(b.url,b.data);a.document.documentElement.appendChild(l)});return!0===b.background?z:q(z)},setCompletionCallback:function(a){z=a}}}(window,x),M=function(a){function c(g,e,a,b,c,d,h){for(;a<b;a++){var f=e[a];null!=f&&t(g,k(f,c,h),d)}}function k(g,e,a){var b=g.tag;null!=g.attrs&&B(g.attrs,g,e);if("string"===typeof b)switch(b){case "#":return g.dom=n.createTextNode(g.children);case "<":return d(g);case "[":var f=n.createDocumentFragment();null!=g.children&&(b=g.children,c(f,b,0,
b.length,e,null,a));g.dom=f.firstChild;g.domSize=f.childNodes.length;return f;default:var h=g.tag;switch(g.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var l=(b=g.attrs)&&b.is,h=a?l?n.createElementNS(a,h,{is:l}):n.createElementNS(a,h):l?n.createElement(h,{is:l}):n.createElement(h);g.dom=h;if(null!=b)for(f in l=a,b)v(g,f,null,b[f],l);null!=g.attrs&&null!=g.attrs.contenteditable?p(g):(null!=g.text&&(""!==g.text?h.textContent=g.text:g.children=
[w("#",void 0,void 0,g.text,void 0,void 0)]),null!=g.children&&(f=g.children,c(h,f,0,f.length,e,null,a),e=g.attrs,"select"===g.tag&&null!=e&&("value"in e&&v(g,"value",null,e.value,void 0),"selectedIndex"in e&&v(g,"selectedIndex",null,e.selectedIndex,void 0))));return h}else{g.state=Object.create(g.tag);f=g.tag.view;if(null!=f.reentrantLock)g=L;else if(f.reentrantLock=!0,B(g.tag,g,e),g.instance=w.normalize(f.call(g.state,g)),f.reentrantLock=null,null!=g.instance){if(g.instance===g)throw Error("A view cannot return the vnode it received as arguments");
e=k(g.instance,e,a);g.dom=g.instance.dom;g.domSize=null!=g.dom?g.instance.domSize:0;g=e}else g.domSize=0,g=L;return g}}function d(g){var e={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(g.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",e=n.createElement(e);e.innerHTML=g.children;g.dom=e.firstChild;g.domSize=e.childNodes.length;g=n.createDocumentFragment();for(var a;a=e.firstChild;)g.appendChild(a);return g}function h(g,e,a,b,
d,h){if(e!==a&&(null!=e||null!=a))if(null==e)c(g,a,0,a.length,b,d,void 0);else if(null==a)z(e,0,e.length,a);else{if(e.length===a.length){for(var f=!1,u=0;u<a.length;u++)if(null!=a[u]&&null!=e[u]){f=null==a[u].key&&null==e[u].key;break}if(f){for(u=0;u<e.length;u++)e[u]!==a[u]&&(null==e[u]&&null!=a[u]?t(g,k(a[u],b,h),l(e,u+1,d)):null==a[u]?z(e,u,u+1,a):m(g,e[u],a[u],b,l(e,u+1,d),!1,h));return}}a:{if(null!=e.pool&&Math.abs(e.pool.length-a.length)<=Math.abs(e.length-a.length)&&(f=a[0]&&a[0].children&&
a[0].children.length||0,Math.abs((e.pool[0]&&e.pool[0].children&&e.pool[0].children.length||0)-f)<=Math.abs((e[0]&&e[0].children&&e[0].children.length||0)-f))){f=!0;break a}f=!1}f&&(e=e.concat(e.pool));for(var n=u=0,p=e.length-1,r=a.length-1,A;p>=u&&r>=n;){var y=e[u],v=a[n];if(y!==v||f)if(null==y)u++;else if(null==v)n++;else if(y.key===v.key)u++,n++,m(g,y,v,b,l(e,u,d),f,h),f&&y.tag===v.tag&&t(g,q(y),d);else if(y=e[p],y!==v||f)if(null==y)p--;else if(null==v)n++;else if(y.key===v.key)m(g,y,v,b,l(e,
p+1,d),f,h),(f||n<r)&&t(g,q(y),l(e,u,d)),p--,n++;else break;else p--,n++;else u++,n++}for(;p>=u&&r>=n;){y=e[p];v=a[r];if(y!==v||f)if(null==y)p--;else{if(null!=v)if(y.key===v.key)m(g,y,v,b,l(e,p+1,d),f,h),f&&y.tag===v.tag&&t(g,q(y),d),null!=y.dom&&(d=y.dom),p--;else{if(!A){A=e;var y=p,C={},w;for(w=0;w<y;w++){var x=A[w];null!=x&&(x=x.key,null!=x&&(C[x]=w))}A=C}null!=v&&(y=A[v.key],null!=y?(C=e[y],m(g,C,v,b,l(e,p+1,d),f,h),t(g,q(C),d),e[y].skip=!0,null!=C.dom&&(d=C.dom)):(v=k(v,b,void 0),t(g,v,d),d=
v))}r--}else p--,r--;if(r<n)break}c(g,a,n,r+1,b,d,h);z(e,u,p+1,a)}}function m(a,e,f,c,l,n,r){var g=e.tag;if(g===f.tag){f.state=e.state;f.events=e.events;var u;var z;null!=f.attrs&&"function"===typeof f.attrs.onbeforeupdate&&(u=f.attrs.onbeforeupdate.call(f.state,f,e));"string"!==typeof f.tag&&"function"===typeof f.tag.onbeforeupdate&&(z=f.tag.onbeforeupdate.call(f.state,f,e));void 0===u&&void 0===z||u||z?u=!1:(f.dom=e.dom,f.domSize=e.domSize,f.instance=e.instance,u=!0);if(!u)if(null!=f.attrs&&K(f.attrs,
f,c,n),"string"===typeof g)switch(g){case "#":e.children.toString()!==f.children.toString()&&(e.dom.nodeValue=f.children);f.dom=e.dom;break;case "<":e.children!==f.children?(q(e),t(a,d(f),l)):(f.dom=e.dom,f.domSize=e.domSize);break;case "[":h(a,e.children,f.children,c,l,r);e=0;c=f.children;f.dom=null;if(null!=c){for(var A=0;A<c.length;A++)a=c[A],null!=a&&null!=a.dom&&(null==f.dom&&(f.dom=a.dom),e+=a.domSize||1);1!==e&&(f.domSize=e)}break;default:a=r;l=f.dom=e.dom;switch(f.tag){case "svg":a="http://www.w3.org/2000/svg";
break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===f.tag&&(null==f.attrs&&(f.attrs={}),null!=f.text&&(f.attrs.value=f.text,f.text=void 0));n=e.attrs;r=f.attrs;g=a;if(null!=r)for(A in r)v(f,A,n&&n[A],r[A],g);if(null!=n)for(A in n)null!=r&&A in r||("className"===A&&(A="class"),"o"!==A[0]||"n"!==A[1]||D(A)?"key"!==A&&f.dom.removeAttribute(A):x(f,A,void 0));null!=f.attrs&&null!=f.attrs.contenteditable?p(f):null!=e.text&&null!=f.text&&""!==f.text?e.text.toString()!==f.text.toString()&&
(e.dom.firstChild.nodeValue=f.text):(null!=e.text&&(e.children=[w("#",void 0,void 0,e.text,void 0,e.dom.firstChild)]),null!=f.text&&(f.children=[w("#",void 0,void 0,f.text,void 0,void 0)]),h(l,e.children,f.children,c,null,a))}else f.instance=w.normalize(f.tag.view.call(f.state,f)),K(f.tag,f,c,n),null!=f.instance?(null==e.instance?t(a,k(f.instance,c,r),l):m(a,e.instance,f.instance,c,l,n,r),f.dom=f.instance.dom,f.domSize=f.instance.domSize):null!=e.instance?(b(e.instance,null),f.dom=void 0,f.domSize=
0):(f.dom=e.dom,f.domSize=e.domSize)}else b(e,null),t(a,k(f,c,r),l)}function q(a){var g=a.domSize;if(null!=g||null==a.dom){var b=n.createDocumentFragment();if(0<g){for(a=a.dom;--g;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function l(a,e,b){for(;e<a.length;e++)if(null!=a[e]&&null!=a[e].dom)return a[e].dom;return b}function t(a,e,b){b&&b.parentNode?a.insertBefore(e,b):a.appendChild(e)}function p(a){var e=a.children;if(null!=e&&1===e.length&&"<"===e[0].tag)e=
e[0].children,a.dom.innerHTML!==e&&(a.dom.innerHTML=e);else if(null!=a.text||null!=e&&0!==e.length)throw Error("Child node of a contenteditable must be trusted");}function z(a,e,f,c){for(;e<f;e++){var g=a[e];null!=g&&(g.skip?g.skip=!1:b(g,c))}}function b(a,e){function b(){if(++c===g&&(r(a),a.dom)){var b=a.domSize||1;if(1<b)for(var f=a.dom;--b;){var d=f.nextSibling,h=d.parentNode;null!=h&&h.removeChild(d)}b=a.dom;f=b.parentNode;null!=f&&f.removeChild(b);if(b=null!=e&&null==a.domSize)b=a.attrs,b=!(null!=
b&&(b.oncreate||b.onupdate||b.onbeforeremove||b.onremove));b&&"string"===typeof a.tag&&(e.pool?e.pool.push(a):e.pool=[a])}}var g=1,c=0;if(a.attrs&&a.attrs.onbeforeremove){var d=a.attrs.onbeforeremove.call(a.state,a);null!=d&&"function"===typeof d.then&&(g++,d.then(b,b))}"string"!==typeof a.tag&&a.tag.onbeforeremove&&(d=a.tag.onbeforeremove.call(a.state,a),null!=d&&"function"===typeof d.then&&(g++,d.then(b,b)));b()}function r(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,a);"string"!==
typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)r(a.instance);else if(a=a.children,Array.isArray(a))for(var b=0;b<a.length;b++){var g=a[b];null!=g&&r(g)}}function v(a,b,c,d,h){var e=a.dom;if("key"!==b&&"is"!==b&&(c!==d||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===n.activeElement||"object"===typeof d)&&"undefined"!==typeof d&&!D(b)){var g=b.indexOf(":");if(-1<g&&"xlink"===b.substr(0,g))e.setAttributeNS("http://www.w3.org/1999/xlink",b.slice(g+
1),d);else if("o"===b[0]&&"n"===b[1]&&"function"===typeof d)x(a,b,d);else if("style"===b)if(a=c,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var f in d)e.style[f]=d[f];if(null!=a&&"string"!==typeof a)for(f in a)f in d||(e.style[f]="")}else b in e&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===h&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&"value"===
b&&a.dom.value===d&&a.dom===n.activeElement||"select"===a.tag&&"value"===b&&a.dom.value===d&&a.dom===n.activeElement||"option"===a.tag&&"value"===b&&a.dom.value===d||(e[b]=d):"boolean"===typeof d?d?e.setAttribute(b,""):e.removeAttribute(b):e.setAttribute("className"===b?"class":b,d)}}function D(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function x(a,b,d){var e=a.dom,c="function"!==typeof H?d:function(a){var b=d.call(e,a);H.call(e,
a);return b};if(b in e)e[b]="function"===typeof d?c:null;else{var f=b.slice(2);void 0===a.events&&(a.events={});a.events[b]!==c&&(null!=a.events[b]&&e.removeEventListener(f,a.events[b],!1),"function"===typeof d&&(a.events[b]=c,e.addEventListener(f,a.events[b],!1)))}}function B(a,b,d){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&d.push(a.oncreate.bind(b.state,b))}function K(a,b,d,c){c?B(a,b,d):"function"===typeof a.onupdate&&d.push(a.onupdate.bind(b.state,
b))}var n=a.document,L=n.createDocumentFragment(),H;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var d=[],e=n.activeElement;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);h(a,a.vnodes,w.normalizeChildren(b),d,null,void 0);a.vnodes=b;for(var c=0;c<d.length;c++)d[c]();n.activeElement!==e&&e.focus()},setEventCallback:function(a){return H=a}}},F=function(a){function c(a){a=d.indexOf(a);-1<a&&d.splice(a,
2)}function k(){for(var a=1;a<d.length;a+=2)d[a]()}a=M(a);a.setEventCallback(function(a){!1!==a.redraw&&k()});var d=[];return{subscribe:function(a,k){c(a);d.push(a,O(k))},unsubscribe:c,redraw:k,render:a.render}}(window);I.setCompletionCallback(F.redraw);B.mount=function(a){return function(c,k){if(null===k)a.render(c,[]),a.unsubscribe(c);else{if(null==k.view)throw Error("m.mount(element, component) expects a component, not a vnode");a.subscribe(c,function(){a.render(c,w(k))});a.redraw()}}}(F);var Q=
x,J=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var c={},k={},d=0;d<a.length;d++){var h=a[d].split("="),m=decodeURIComponent(h[0]),h=2===h.length?decodeURIComponent(h[1]):"";"true"===h?h=!0:"false"===h&&(h=!1);var q=m.split(/\]\[?|\[/),l=c;-1<m.indexOf("[")&&q.pop();for(var t=0;t<q.length;t++){var m=q[t],p=q[t+1],p=""==p||!isNaN(parseInt(p,10)),z=t===q.length-1;""===m&&(m=q.slice(0,t).join(),null==k[m]&&(k[m]=0),m=k[m]++);null==l[m]&&(l[m]=z?h:p?[]:
{});l=l[m]}}return c},R=function(a){function c(d){var c=a.location[d].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===d&&"/"!==c[0]&&(c="/"+c);return c}function k(a){return function(){null==q&&(q=m(function(){q=null;a()}))}}function d(a,d,c){var b=a.indexOf("?"),h=a.indexOf("#"),l=-1<b?b:-1<h?h:a.length;if(-1<b){var b=J(a.slice(b+1,-1<h?h:a.length)),k;for(k in b)d[k]=b[k]}if(-1<h)for(k in d=J(a.slice(h+1)),d)c[k]=d[k];return a.slice(0,l)}var h="function"===typeof a.history.pushState,
m="function"===typeof setImmediate?setImmediate:setTimeout,q,l={prefix:"#!",getPath:function(){switch(l.prefix.charAt(0)){case "#":return c("hash").slice(l.prefix.length);case "?":return c("search").slice(l.prefix.length)+c("hash");default:return c("pathname").slice(l.prefix.length)+c("search")+c("hash")}},setPath:function(c,k,m){var b={},r={};c=d(c,b,r);if(null!=k){for(var v in k)b[v]=k[v];c=c.replace(/:([^\/]+)/g,function(a,c){delete b[c];return k[c]})}(v=E(b))&&(c+="?"+v);(r=E(r))&&(c+="#"+r);
h?(r=m?m.state:null,v=m?m.title:null,a.onpopstate(),m&&m.replace?a.history.replaceState(r,v,l.prefix+c):a.history.pushState(r,v,l.prefix+c)):a.location.href=l.prefix+c},defineRoutes:function(c,m,q){function b(){var b=l.getPath(),h={},k=d(b,h,h),p=a.history.state;if(null!=p)for(var t in p)h[t]=p[t];for(var z in c)if(p=new RegExp("^"+z.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),p.test(k)){k.replace(p,function(){for(var a=z.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,
1,-2),k=0;k<a.length;k++)h[a[k].replace(/:|\./g,"")]=decodeURIComponent(d[k]);m(c[z],h,b,z)});return}q(b,h)}h?a.onpopstate=k(b):"#"===l.prefix.charAt(0)&&(a.onhashchange=b);b()}};return l};B.route=function(a,c){var k=R(a),d=function(a){return a},h,m,q,l,t,p=function(a,b,p){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var r=function(){null!=h&&c.render(a,h(w(m,q.key,q)))},z=function(){k.setPath(b,null,{replace:!0})};k.defineRoutes(p,function(a,b,c){var k=
t=function(a,n){k===t&&(m=null!=n&&"function"===typeof n.view?n:"div",q=b,l=c,t=null,h=(a.render||d).bind(a),r())};a.view?k({},a):a.onmatch?Q.resolve(a.onmatch(b,c)).then(function(b){k(a,b)},z):k(a,"div")},z);c.subscribe(a,r)};p.set=function(a,b,c){null!=t&&(c={replace:!0});t=null;k.setPath(a,b,c)};p.get=function(){return l};p.prefix=function(a){k.prefix=a};p.link=function(a){a.dom.setAttribute("href",k.prefix+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||
(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(k.prefix)&&(a=a.slice(k.prefix.length)),p.set(a,void 0,void 0))}};return p}(window,F);B.withAttr=function(a,c,k){return function(d){return c.call(k||this,a in d.currentTarget?d.currentTarget[a]:d.currentTarget.getAttribute(a))}};var S=M(window);B.render=S.render;B.redraw=F.redraw;B.request=I.request;B.jsonp=I.jsonp;B.parseQueryString=J;B.buildQueryString=E;B.version="1.0.0-rc.7";B.vnode=w;"undefined"!==typeof module?module.exports=
B:window.m=B};

View file

@ -104,7 +104,7 @@ o.spec("component", function() {
visible = false
render(root, [{tag: component}])
o(root.firstChild.nodeValue).equals("false")
o(root.firstChild.nodeValue).equals("")
})
o("updates root from null to null", function() {
var component = {
@ -232,7 +232,7 @@ o.spec("component", function() {
render(root, [{tag: component}])
o(root.firstChild.nodeType).equals(3)
o(root.firstChild.nodeValue).equals("false")
o(root.firstChild.nodeValue).equals("")
})
o("can return null", function() {
var component = {
@ -668,7 +668,7 @@ o.spec("component", function() {
function init(vnode) {
o(vnode.state.data).deepEquals(data)
o(vnode.state.data).equals(data)
//inherits state via prototype
component.x = 1
o(vnode.state.x).equals(1)

View file

@ -229,7 +229,7 @@ o.spec("hyperscript", function() {
o("handles falsy boolean single child", function() {
var vnode = m("div", {}, [false])
o(vnode.text).equals(false)
o(vnode.text).equals("")
})
o("handles null single child", function() {
var vnode = m("div", {}, [null])
@ -261,7 +261,7 @@ o.spec("hyperscript", function() {
var vnode = m("div", {}, [false, true])
o(vnode.children[0].tag).equals("#")
o(vnode.children[0].children).equals(false)
o(vnode.children[0].children).equals("")
o(vnode.children[1].tag).equals("#")
o(vnode.children[1].children).equals(true)
})
@ -353,10 +353,16 @@ o.spec("hyperscript", function() {
o(vnode.text).equals(true)
})
o("handles attr and single falsy boolean text child", function() {
var vnode = m("div", {a: "b"}, [0])
o(vnode.attrs.a).equals("b")
o(vnode.text).equals(0)
})
o("handles attr and single false boolean text child", function() {
var vnode = m("div", {a: "b"}, [false])
o(vnode.attrs.a).equals("b")
o(vnode.text).equals(false)
o(vnode.text).equals("")
})
o("handles attr and single text child unwrapped", function() {
var vnode = m("div", {a: "b"}, "c")

View file

@ -48,10 +48,10 @@ o.spec("normalize", function() {
o(node.tag).equals("#")
o(node.children).equals(true)
})
o("normalizes falsy boolean into text node", function() {
o("normalizes falsy boolean into empty text node", function() {
var node = Vnode.normalize(false)
o(node.tag).equals("#")
o(node.children).equals(false)
o(node.children).equals("")
})
})

View file

@ -16,4 +16,10 @@ o.spec("normalizeChildren", function() {
o(children[0].tag).equals("#")
o(children[0].children).equals("a")
})
o("normalizes `false` values into empty string text nodes", function() {
var children = Vnode.normalizeChildren([false])
o(children[0].tag).equals("#")
o(children[0].children).equals("")
})
})

View file

@ -3,7 +3,7 @@ function Vnode(tag, key, attrs, children, text, dom) {
}
Vnode.normalize = function(node) {
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node, undefined, undefined)
if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node === false ? "" : node, undefined, undefined)
return node
}
Vnode.normalizeChildren = function normalizeChildren(children) {