From e458411c1198a636d784c22b0b48bc245e1fcc8e Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Thu, 17 Nov 2016 02:30:32 +0000 Subject: [PATCH 1/9] Bundled output for commit 0bd6d4b2f630125312c0d4df6cc9f70486acb046 [skip ci] --- mithril.js | 2 +- mithril.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index 677850ad..a037e78d 100644 --- a/mithril.js +++ b/mithril.js @@ -1120,7 +1120,7 @@ m.request = requestService.request m.jsonp = requestService.jsonp m.parseQueryString = parseQueryString m.buildQueryString = buildQueryString -m.version = "1.0.0-rc.4" +m.version = "1.0.0-rc.5" if (typeof module !== "undefined") module["exports"] = m else window.m = m } \ No newline at end of file diff --git a/mithril.min.js b/mithril.min.js index 927e202b..aea30f39 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -37,4 +37,4 @@ b("hash");default:return b("pathname").slice(r.length)+b("search")+b("hash")}}fu t;return{setPrefix:function(a){r=a},getPath:l,setPath:h,defineRoutes:function(b,h,f){function n(){var a=l(),k={},m=d(a,k,k),n;for(n in b){var q=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(q.test(m)){m.replace(q,function(){for(var d=n.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),l=0;l Date: Thu, 17 Nov 2016 14:07:20 -0500 Subject: [PATCH 2/9] Add note about JSON parsing behaviour with extract callback --- docs/request.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/request.md b/docs/request.md index 8377ba09..e0d5c2fb 100644 --- a/docs/request.md +++ b/docs/request.md @@ -32,7 +32,7 @@ Argument | Type | Required | Descript `options.type` | `any = Function(any)` | No | A constructor to be applied to each object in the response. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function). `options.serialize` | `string = Function(any)` | No | A serialization method to be applied to `data`. Defaults to `JSON.stringify`, or if `options.data` is an instance of [`FormData`](https://developer.mozilla.org/en/docs/Web/API/FormData), defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function) (i.e. `function(value) {return value}`). `options.deserialize` | `any = Function(string)` | No | A deserialization method to be applied to the response. Defaults to a small wrapper around `JSON.parse` that returns `null` for empty responses. -`options.extract` | `string = Function(xhr, options)` | No | A hook to specify how the XMLHttpRequest response should be read. Useful for reading response headers and cookies. Defaults to a function that returns `xhr.responseText`. If defined, the `xhr` parameter is the XMLHttpRequest instance used for the request, and `options` is the object that was passed to the `m.request` call. If a custom `extract` callback is set, `options.deserialize` is ignored. +`options.extract` | `string = Function(xhr, options)` | No | A hook to specify how the XMLHttpRequest response should be read. Useful for reading response headers and cookies. Defaults to a function that returns `xhr.responseText`. If defined, the `xhr` parameter is the XMLHttpRequest instance used for the request, and `options` is the object that was passed to the `m.request` call. If a custom `extract` callback is set, `options.deserialize` is ignored and the string returned from the extract callback will not be parsed as JSON. `options.useBody` | `Boolean` | No | Force the use of the HTTP body section for `data` in `GET` requests when set to `true`, or the use of querystring for other HTTP methods when set to `false`. Defaults to `false` for `GET` requests and `true` for other methods. **returns** | `Promise` | | A promise that resolves to the response data, after it has been piped through the `extract`, `deserialize` and `type` methods @@ -186,7 +186,7 @@ Sometimes, it is desirable to abort a request. For example, in an autocompleter/ var searchXHR = null function search() { abortPreviousSearch() - + m.request({ method: "GET", url: "/api/v1/users", @@ -223,7 +223,7 @@ Next, you need to create a [`FormData`](https://developer.mozilla.org/en/docs/We ```javascript function upload(e) { var file = e.target.files[0] - + var data = new FormData() data.append("myfile", file) } @@ -234,10 +234,10 @@ Next, you need to call `m.request` and set `options.method` to an HTTP method th ```javascript function upload(e) { var file = e.target.files[0] - + var data = new FormData() data.append("myfile", file) - + m.request({ method: "POST", url: "/api/v1/upload", @@ -261,12 +261,12 @@ m.render(document.body, [ function upload(e) { var files = e.target.files - + var data = new FormData() for (var i = 0; i < files.length; i++) { data.append("file" + i, file) } - + m.request({ method: "POST", url: "/api/v1/upload", @@ -297,10 +297,10 @@ m.mount(document.body, { function upload(e) { var file = e.target.files[0] - + var data = new FormData() data.append("myfile", file) - + m.request({ method: "POST", url: "/api/v1/upload", @@ -308,7 +308,7 @@ function upload(e) { config: function(xhr) { xhr.addEventListener("progress", function(e) { progress = e.loaded / e.total - + m.redraw() // tell Mithril that data changed and a re-render is needed }) } From 6e1402dd1bf09b60acabdb89554fc93b71510c4d Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 18 Nov 2016 23:26:02 -0500 Subject: [PATCH 3/9] docs for promise --- docs/promise.md | 289 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 docs/promise.md diff --git a/docs/promise.md b/docs/promise.md new file mode 100644 index 00000000..9a659d74 --- /dev/null +++ b/docs/promise.md @@ -0,0 +1,289 @@ +# Promise(executor) + +- [API](#api) +- [Static members](#static-members) + - [Promise.resolve](#promiseresolve) + - [Promise.reject](#promisereject) + - [Promise.all](#promiseall) + - [Promise.race](#promiserace) +- [Instance members](#static-members) + - [promise.then](#promisethen) + - [promise.catch](#promisecatch) +- [How it works](#how-it-works) +- [Promise chaining](#promise-chaining) +- [Promise absorption](#promise-absorption) +- [Error handling](#error-handling) +- [Shorthands](#shorthands) +- [Waiting for multiple promises](#waiting-for-multiple-promises) + +--- + +### API + +`promise = new Promise(executor)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`executor` | `(Function, Function) -> any` | Yes | A function that determines how the promise will be resolved or rejected +**returns** | `Promise` | | Returns a promise + +[How to read signatures](signatures.md) + +--- + +##### executor + +`executor(resolve, reject)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`resolve` | `any -> any` | No | Call this function to resolve the promise +`reject` | `any -> any` | No | Call this function to reject the promise +**returns** | | | The return value is ignored + +[How to read signatures](signatures.md) + +--- + +#### Static members + +##### Promise.resolve + +`promise = Promise.resolve(value)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`value` | `any` | No | A value to resolve to +**returns** | `Promise` | | A promise resolved to `value` + +[How to read signatures](signatures.md) + +--- + +##### Promise.reject + +`promise = Promise.reject(value)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`value` | `any` | No | A value to reject as +**returns** | `Promise` | | A rejected promise with `value` as its reason + +[How to read signatures](signatures.md) + +--- + +##### Promise.all + +`promise = Promise.all(promises)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`promises` | `Array` | Yes | A list of promises to wait for. If an item is not a promise, it's equivalent to calling `Promise.resolve` on it +**returns** | `Promise` | | A promise that resolves only after all `promises` resolve, or rejects if any of them are rejected. + +[How to read signatures](signatures.md) + +--- + +##### Promise.race + +`promise = Promise.race(promises)` + +Argument | Type | Required | Description +----------- | ----------------------------- | -------- | --- +`promises` | `Array` | Yes | A list of promises to wait for. If an item is not a promise, it's equivalent to calling `Promise.resolve` on it +**returns** | `Promise` | | A promise that resolves as soon as one of the `promises` is resolved or rejected. + +[How to read signatures](signatures.md) + +--- + +#### Instance members + +##### promise.then + +`nextPromise = promise.then(onFulfilled, onRejected)` + +Argument | Type | Required | Description +------------- | ----------------------- | -------- | --- +`onFulfilled` | `any -> (any|Promise)` | No | A function that is called if the promise is resolved. The first parameter of this function is the value that this promise was resolved with. If the return value of this function is not a Promise, it is used as the value for resolving `nextPromise`. If the returned value is a Promise, the value of `nextPromise` depends on the inner Promise's status. If this function throws, `nextPromise` is rejected with the error as its reason. If `onFulfilled` is `null`, it's ignored +`onRejected` | `any -> (any|Promise)` | No | A function that is called when the promise is rejected. The first parameter of this function is a value that represents the reason why the promise was rejected. If the return value of this function is not a Promise, it is used as the value for resolving `nextPromise`. If the returned value is a Promise, then value of `nextPromise` depends on the inner Promise's status. If this function throws, `nextPromise` is rejected with the error as its reason. If `onRejected` is `null`, it's ignored +**returns** | `Promise` | | A promise whose value depends on the status of the current promise + +[How to read signatures](signatures.md) + +--- + +##### promise.catch + +`nextPromise = promise.catch(onRejected)` + +Argument | Type | Required | Description +------------- | ----------------------- | -------- | --- +`onRejected` | `any -> (any|Promise)` | No | A function that is called when the promise is rejected. The first parameter of this function is a value that represents the reason why the promise was rejected. If the return value of this function is not a Promise, it is used as the value for resolving `nextPromise`. If the returned value is a Promise, then value of `nextPromise` depends on the inner Promise's status. If this function throws, `nextPromise` is rejected with the error as its reason. If `onRejected` is `null`, it's ignored +**returns** | `Promise` | | A promise whose value depends on the status of the current promise + +[How to read signatures](signatures.md) + +--- + +### How it works + +A Promise is an object that represents a value which may be available in the future + +```javascript +// this promise resolves after one second +var promise = new Promise(function(resolve, reject) { + setTimeout(function() { + resolve("hello") + }, 1000) +}) + +promise.then(function(value) { + // logs "hello" after one second + console.log(value) +}) +``` + +Promises are useful for working with [asynchronous](https://en.wikipedia.org/wiki/Asynchrony_(computer_programming)) APIs, such as [`m.request`](request.md) + +Asynchronous APIs are those which typically take a long time to run, and therefore would take too long to return a value using the `return` statement of a function. Instead, they do their work in the background, allowing other Javascript code to run in the meantime. When they are done, they call a function with their results. + +The `m.request` function takes time to run because it makes an HTTP request to a remote server and has to wait for a response, which may take several milliseconds due to network latency. + +--- + +### Promise chaining + +Promises can be chained. Returning a value from a `then` callback makes it available as the argument to the next `then` callback. This allows refactoring code into smaller functions + +```javascript +function getUsers() {return m.request("/api/v1/users")} + +// AVOID: hard to test god functions +getUsers().then(function(users) { + var firstTen = users.slice(0, 9) + var firstTenNames = firstTen.map(function(user) {return user.firstName + " " + user.lastName}) + alert(firstTenNames) +}) + +// PREFER: easy to test small functions +function getFirstTen(items) {return items.slice(0, 9)} +function getUserName(user) {return user.firstName + " " + user.lastName} +function getUserNames(users) {return users.map(getUserName)} + +getUsers() + .then(getFirstTen) + .then(getUserNames) + .then(alert) +``` + +In the refactored code, `getUsers()` returns a promise, and we chain three callbacks. When `getUsers()` resolves, the `getFirstTen` function is called with a list of users as its first argument. This function returns a list of ten items. `getUserNames` returns a list of names for the 10 items that were passed as the argument to it. Finally, the list of names is alerted. + +In the original code above, it's very difficult to test the god function since you must make an HTTP request to run the code, and there's an `alert()` call at the end of the function + +In the refactored version, it's trivial to test whether `getFirstTen` has any off-by-one errors, or whether we forgot to add a space between the first and last names in `getUserName`. + +--- + +### Promise absorption + +Promises absorb other promises. Basically, this means you can never receive a Promise as an argument to `onFulfilled` or `onRejected` callbacks for `then` and `catch` methods. This feature allows us to flatten nested promises to make code more manageable. + +```Javascript +function searchUsers(q) {return m.request("/api/v1/users/search", {data: {q: q}})} +function getUserProjects() {return m.request("/api/v1/user/" + id + "/projects")} + +// AVOID: pyramid of doom +searchUsers("John").then(function(users) { + getUserProjects(users[0].id).then(function(projects) { + var titles = projects.map(function(project) {return project.title}) + alert(titles) + }) +}) + +// PREFER: flat code flow +function getFirstId(items) {return items[0].id} +function getProjectTitles(projects) {return projects.map(getProjectTitle)} +function getProjectTitle(project) {return project.title} + +searchUsers("John") + .then(getFirstId) + .then(getUserProjects) + .then(getProjectTitles) + .then(alert) +``` + +In the refactored code, `getFirstId` returns an id, which is passed as the first argument to `getUserProjects`. That, in turn, returns a promise that resolves to a list of projects. This promise is absorbed, so the first argument to `getProjectTitles` is not a promise, but the list of projects. `getProjectTitles` returns a list of titles, and that list is finally alerted. + +--- + +### Error handling + +Promises can propagate errors to appropriate handlers. + +```javascript +searchUsers("John") + .then(getFirstId) + .then(getUserProjects) + .then(getProjectTitles) + .then(alert) + .catch(function(e) { + console.error(e) + }) +``` + +Here's the previous example with error handling. The `searchUsers` function could fail if the network was offline, resulting in an error. In that case, none of the `.then` callbacks would be triggered, and the `.catch` callback would log the error to console. + +If the request in `getUserProjects` failed, then similarly, `getProjectTitles` and `alert` would not be called. Again, the `.catch` callback would log the error. + +The error handler would also catch a null reference exception if `searchUsers` returned no results, and `getFirstId` attempted to access the `id` property of a non-existent array item. + +Thanks to these error propagation semantics, it's easy to keep each function small and testable without sprinkling `try`/`catch` blocks everywhere. + +--- + +### Shorthands + +Sometimes, you already have a value, but want to wrap it in a Promise. It's for this purpose that `Promise.resolve` and `Promise.reject` exist. + +```javascript +// suppose this list came from localStorage +var users = [{id: 1, firstName: "John", lastName: "Doe"}] + +// in that case, `users` may or may not exist depending on whether there was data in localStorage +var promise = users ? Promise.resolve(users) : getUsers() +promise + .then(getFirstTen) + .then(getUserNames) + .then(alert) +``` + +--- + +### Waiting for multiple promises + +In some occasions, you may need to make HTTP requests in parallel, and run code after all requests complete. This can be accomplished by `Promise.all` + +```javascript +Promise.all([ + searchUsers("John"), + searchUsers("Mary"), +]) +.then(function(data) { + // data[0] is an array of users whose names are John + // data[1] is an array of users whose names are Mary + + //the returned value is equivalent to [ + // getUserNames(data[0]), + // getUserNames(data[1]), + //] + return data.map(getUserNames) +}) +.then(alert) +``` + +In the example above, there are two user searches happening in parallel. Once they both complete, we take the names of all the users and alert them. + +This example also illustrates another benefit of smaller functions: we reused the `getUserNames` function we had created above. From 3a1124f3ec637fcf9c6913d60107a89ed71e6dad Mon Sep 17 00:00:00 2001 From: eladzlot Date: Sun, 20 Nov 2016 14:13:35 +0200 Subject: [PATCH 4/9] simplify array operators in stream --- stream/stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stream/stream.js b/stream/stream.js index f1cc33df..9a29ab02 100644 --- a/stream/stream.js +++ b/stream/stream.js @@ -44,7 +44,7 @@ function updateState(stream, value) { } function updateDependency(stream, mustSync) { var state = stream._state, parents = state.parents - if (parents.length > 0 && parents.filter(active).length === parents.length && (mustSync || parents.filter(changed).length > 0)) { + if (parents.length > 0 && parents.every(active) && (mustSync || parents.some(changed))) { var value = stream._state.derive() if (value === HALT) return false updateState(stream, value) @@ -56,7 +56,7 @@ function finalize(stream) { } function combine(fn, streams) { - if (streams.length > streams.filter(valid).length) throw new Error("Ensure that each item passed to m.prop.combine/m.prop.merge is a stream") + if (!streams.every(valid)) throw new Error("Ensure that each item passed to m.prop.combine/m.prop.merge is a stream") return initDependency(createStream(), streams, function() { return fn.apply(this, streams.concat([streams.filter(changed)])) }) From 2a6011e2c1765fe46e3616277f18d1f6093689a9 Mon Sep 17 00:00:00 2001 From: spacejack Date: Sun, 20 Nov 2016 17:58:23 -0500 Subject: [PATCH 5/9] Add notes about passing data to components, avoid inadvertant lifecycle hooks. --- docs/components.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/components.md b/docs/components.md index 7f5d561f..bf61a6ee 100644 --- a/docs/components.md +++ b/docs/components.md @@ -26,6 +26,28 @@ m(Example) --- +### Passing data to components + +Data can be passed to component instances through an `attrs` object as a parameter in the hyperscript function: + +```javascript +m(Example, {name: "Floyd"}) +``` + +`attrs` data can be accessed in the component's view or lifecycle methods via the `vnode`: + +```javascript +var Example = { + view: function (vnode) { + return m("div", "Hello, " + vnode.attrs.name) + } +} +``` + +NOTE: Lifecycle methods can also be provided via attrs, so you should avoid using the lifecycle method names for your own callbacks as they will be invoked by Mithril. Use lifecycle methods in `attrs` only when you specifically wish to create lifecycle hooks. + +--- + ### Lifecycle methods Components can have the same [lifecycle methods](lifecycle-methods.md) as virtual DOM nodes: `oninit`, `oncreate`, `onupdate`, `onbeforeremove`, `onremove` and `onbeforeupdate`. @@ -69,6 +91,8 @@ m(ComponentWithHooks, {oninit: initialize}) Lifecycle methods in vnodes do not override component methods, nor vice versa. Component lifecycle methods are always run after the vnode's corresponding method. +Take care not to use lifecycle method names for your own callback function names in vnodes. + To learn more about lifecycle methods, [see the lifecycle methods page](lifecycle-methods.md). --- From 848f79c2c75bfdebf7ce405a4b7a480fac2ea251 Mon Sep 17 00:00:00 2001 From: Rasmus Porsager Date: Mon, 21 Nov 2016 02:12:56 +0100 Subject: [PATCH 6/9] Don't set same value of options in focused select - fixes #1413 --- render/render.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/render/render.js b/render/render.js index c2dbd4ca..c706edf3 100644 --- a/render/render.js +++ b/render/render.js @@ -432,6 +432,8 @@ module.exports = function($window) { else if (key in element && !isAttribute(key) && ns === undefined) { //setting input[value] to same value by typing on focused element moves cursor to end in Chrome if (vnode.tag === "input" && key === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return + //setting option[value] to same value while having select open blinks select dropdown in Chrome + if (vnode.tag === "option" && key1 === "value" && vnode.dom.value === value && vnode.dom.parentNode === $doc.activeElement) return element[key] = value } else { From af01c3c89fb44227ee383d08635f3aa2bc4b5583 Mon Sep 17 00:00:00 2001 From: porsager Date: Mon, 21 Nov 2016 02:27:59 +0100 Subject: [PATCH 7/9] Use correct key name --- render/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/render.js b/render/render.js index c706edf3..c74a3e41 100644 --- a/render/render.js +++ b/render/render.js @@ -433,7 +433,7 @@ module.exports = function($window) { //setting input[value] to same value by typing on focused element moves cursor to end in Chrome if (vnode.tag === "input" && key === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return //setting option[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "option" && key1 === "value" && vnode.dom.value === value && vnode.dom.parentNode === $doc.activeElement) return + if (vnode.tag === "option" && key === "value" && vnode.dom.value === value && vnode.dom.parentNode === $doc.activeElement) return element[key] = value } else { From fd484f97664224eaa9b1bfaa473a88c67aa1a72f Mon Sep 17 00:00:00 2001 From: porsager Date: Mon, 21 Nov 2016 09:59:21 +0100 Subject: [PATCH 8/9] Fix options inside optgroups (active check is unnecessary) --- render/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/render.js b/render/render.js index c74a3e41..b05fa302 100644 --- a/render/render.js +++ b/render/render.js @@ -433,7 +433,7 @@ module.exports = function($window) { //setting input[value] to same value by typing on focused element moves cursor to end in Chrome if (vnode.tag === "input" && key === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return //setting option[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "option" && key === "value" && vnode.dom.value === value && vnode.dom.parentNode === $doc.activeElement) return + if (vnode.tag === "option" && key === "value" && vnode.dom.value === value) return element[key] = value } else { From 4002115bbdbf965fd1f69233966bb946c5fa4e11 Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Mon, 21 Nov 2016 14:32:48 +0000 Subject: [PATCH 9/9] Bundled output for commit 5f1f09e9b4b2c2de743fa794dd5fb78a9ec55052 [skip ci] --- mithril.js | 2 ++ mithril.min.js | 80 +++++++++++++++++++++++++------------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/mithril.js b/mithril.js index a037e78d..2a5a6cca 100644 --- a/mithril.js +++ b/mithril.js @@ -757,6 +757,8 @@ var _13 = function($window) { else if (key1 in element && !isAttribute(key1) && ns === undefined) { //setting input[value] to same value by typing on focused element moves cursor to end in Chrome if (vnode.tag === "input" && key1 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return + //setting option[value] to same value while having select open blinks select dropdown in Chrome + if (vnode.tag === "option" && key1 === "value" && vnode.dom.value === value) return element[key1] = value } else { diff --git a/mithril.min.js b/mithril.min.js index aea30f39..35246297 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,40 +1,40 @@ -new function(){function m(a,b,k,d,l,h){return{tag:a,key:b,attrs:k,children:d,text:l,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function t(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 b,k,d=[],l={};b=N.exec(a);){var h=b[1],u=b[2];""===h&&""!==u?k=u:"#"===h?l.id=u:"."===h?d.push(u):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), -l[b[4]]=h||!0)}0a.indexOf("?")?"?":"&";a+=d+f}return a}function u(a){try{return""!== -a?JSON.parse(a):null}catch(w){throw Error(a);}}function q(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;dp.status||304===p.status)b(r(f.type,a));else{var h=Error(p.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(F){d(F)}};n&&null!=f.data?p.send(f.data):p.send()}))}, -jsonp:function(f){return d(new b(function(b,d){var p=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[p]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[p]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[p]};null==f.data&&(f.data={});f.url=l(f.url,f.data);f.data[f.callbackKey||"callback"]=p;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},setCompletionCallback:function(a){v= -a}}}(window,"undefined"!==typeof Promise?Promise:x),I=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1=l&&B>=z;){var y=a[l],m=e[z];if(y!==m||g)if(null!=y&&null!=m&&y.key===m.key)l++,z++,h(c,y,m,f,q(a,l,d),g, -p),g&&y.tag===m.tag&&r(c,u(y),d);else if(y=a[v],y!==m||g)if(null!=y&&null!=m&&y.key===m.key)h(c,y,m,f,q(a,v+1,d),g,p),(g||z=l&&B>=z;){y=a[v];m=e[B];if(y!==m||g)if(null!=y&&null!=m&&y.key===m.key)h(c,y,m,f,q(a,v+1,d),g,p),g&&y.tag===m.tag&&r(c,u(y),d),null!=y.dom&&(d=y.dom),v--;else{if(!w){w=a;var y=v,D={},t;for(t=0;ta.indexOf("?")?"?":"&";a+=d+f}return a}function v(a){try{return""!== +a?JSON.parse(a):null}catch(x){throw Error(a);}}function q(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;dm.status||304===m.status)b(r(f.type,a));else{var h=Error(m.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(F){d(F)}};p&&null!=f.data?m.send(f.data):m.send()}))}, +jsonp:function(f){return d(new b(function(b,d){var m=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,k=a.document.createElement("script");a[m]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[m]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[m]};null==f.data&&(f.data={});f.url=n(f.url,f.data);f.data[f.callbackKey||"callback"]=m;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},setCompletionCallback:function(a){w= +a}}}(window,"undefined"!==typeof Promise?Promise:y),I=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1=u&&B>=n;){var z=a[u],l=e[n];if(z!==l||g)if(null!=z&&null!=l&&z.key===l.key)u++,n++,h(c,z,l,f,q(a,u,d),g, +m),g&&z.tag===l.tag&&r(c,v(z),d);else if(z=a[w],z!==l||g)if(null!=z&&null!=l&&z.key===l.key)h(c,z,l,f,q(a,w+1,d),g,m),(g||n=u&&B>=n;){z=a[w];l=e[B];if(z!==l||g)if(null!=z&&null!=l&&z.key===l.key)h(c,z,l,f,q(a,w+1,d),g,m),g&&z.tag===l.tag&&r(c,v(z),d),null!=z.dom&&(d=z.dom),w--;else{if(!x){x=a;var z=w,D={},t;for(t=0;t