From e9a365c15032d1d5e13849bae75980bbd4ff4ee2 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Mon, 21 Feb 2022 18:47:24 +0100 Subject: [PATCH] Kick promise polyfill --- README.md | 2 +- api/router.js | 1 - api/tests/test-router.js | 1 - docs/animation.md | 2 +- docs/nav-methods.md | 1 - docs/promise.md | 315 ------------ docs/request.md | 4 +- index.js | 1 - mithril.js | 189 ++------ mithril.min.js | 2 +- promise/.eslintrc.js | 15 - promise/polyfill.js | 112 ----- promise/promise.js | 22 - promise/tests/test-promise.js | 720 ---------------------------- promise/tests/test.html | 28 -- render/tests/test-onbeforeremove.js | 1 - request.js | 3 +- request/request.js | 2 +- request/tests/test-jsonp.js | 3 +- request/tests/test-request.js | 5 +- 20 files changed, 41 insertions(+), 1388 deletions(-) delete mode 100644 docs/promise.md delete mode 100644 promise/.eslintrc.js delete mode 100644 promise/polyfill.js delete mode 100644 promise/promise.js delete mode 100644 promise/tests/test-promise.js delete mode 100644 promise/tests/test.html diff --git a/README.md b/README.md index 46b6f845..f0c53553 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ## What is Mithril.js? -A modern client-side JavaScript framework for building Single Page Applications. It's small (10.05 KB gzipped), fast and provides routing and XHR utilities out of the box. +A modern client-side JavaScript framework for building Single Page Applications. It's small (9.34 KB gzipped), fast and provides routing and XHR utilities out of the box. Mithril.js is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍. diff --git a/api/router.js b/api/router.js index 650a86eb..96cf56f8 100644 --- a/api/router.js +++ b/api/router.js @@ -2,7 +2,6 @@ var Vnode = require("../render/vnode") var m = require("../render/hyperscript") -var Promise = require("../promise/promise") var buildPathname = require("../pathname/build") var parsePathname = require("../pathname/parse") diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 6e620ca6..3efe9fa6 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -9,7 +9,6 @@ var m = require("../../render/hyperscript") var coreRenderer = require("../../render/render") var apiMountRedraw = require("../../api/mount-redraw") var apiRouter = require("../../api/router") -var Promise = require("../../promise/promise") o.spec("route", function() { // Note: the `n` parameter used in calls to this are generally found by diff --git a/docs/animation.md b/docs/animation.md index 530a247e..c29884df 100644 --- a/docs/animation.md +++ b/docs/animation.md @@ -90,7 +90,7 @@ var FancyComponent = { `vnode.dom` points to the root DOM element of the component (`
`). We use the classList API here to add an `exit` class to `
`. -Then we return a [Promise](promise.md) that resolves when the `animationend` event fires. When we return a promise from `onbeforeremove`, Mithril.js waits until the promise is resolved and only then it removes the element. In this case, it waits for the exit animation to finish. +Then we return a Promise that resolves when the `animationend` event fires. When we return a promise from `onbeforeremove`, Mithril.js waits until the promise is resolved and only then it removes the element. In this case, it waits for the exit animation to finish. We can verify that both the enter and exit animations work by mounting the `Toggler` component: diff --git a/docs/nav-methods.md b/docs/nav-methods.md index c05957e3..9e829de5 100644 --- a/docs/nav-methods.md +++ b/docs/nav-methods.md @@ -12,7 +12,6 @@ - [m.trust](trust.md) - [m.fragment](fragment.md) - [m.redraw](redraw.md) - - [Promise](promise.md) - Optional - [Stream](stream.md) - Tooling diff --git a/docs/promise.md b/docs/promise.md deleted file mode 100644 index a881e5bc..00000000 --- a/docs/promise.md +++ /dev/null @@ -1,315 +0,0 @@ - - -# Promise(executor) - -- [Description](#description) -- [Signature](#signature) - - [Static members](#static-members) - - [Promise.resolve](#promiseresolve) - - [Promise.reject](#promisereject) - - [Promise.all](#promiseall) - - [Promise.race](#promiserace) - - [Instance members](#instance-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) -- [Multiple promises](#multiple-promises) -- [Why not callbacks](#why-not-callbacks) - ---- - -### Description - -An [ES6 Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) polyfill. - -A Promise is a mechanism for working with asynchronous computations. - -Mithril.js provides a polyfill when the environment does not support Promises. The polyfill can also be referenced specifically via `m.PromisePolyfill`. - ---- - -### Signature - -`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 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", {params: {q: q}})} -function getUserProjects(id) {return m.request("/api/v1/users/" + 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.log(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) -``` - ---- - -### 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. - ---- - -### Why not callbacks - -Callbacks are another mechanism for working with asynchronous computations, and are indeed more adequate to use if an asynchronous computation may occur more than one time (for example, an `onscroll` event handler). - -However, for asynchronous computations that only occur once in response to an action, promises can be refactored more effectively, reducing code smells known as pyramids of doom (deeply nested series of callbacks with unmanaged state being used across several closure levels). - -In addition, promises can considerably reduce boilerplate related to error handling. diff --git a/docs/request.md b/docs/request.md index 8f36ad23..4f5945f1 100644 --- a/docs/request.md +++ b/docs/request.md @@ -25,7 +25,7 @@ Documentation on m.request(), a utility for making XHR/AJAX requests ### Description -Makes XHR (aka AJAX) requests, and returns a [promise](promise.md) +Makes XHR (aka AJAX) requests, and returns a promise ```javascript m.request({ @@ -95,7 +95,7 @@ m.request({ }) ``` -A call to `m.request` returns a [promise](promise.md) and triggers a redraw upon completion of its promise chain. +A call to `m.request` returns a promise and triggers a redraw upon completion of its promise chain. By default, `m.request` assumes the response is in JSON format and parses it into a JavaScript object (or array). diff --git a/index.js b/index.js index 1cd344f2..cf797acd 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,6 @@ m.buildQueryString = require("./querystring/build") m.parsePathname = require("./pathname/parse") m.buildPathname = require("./pathname/build") m.vnode = require("./render/vnode") -m.PromisePolyfill = require("./promise/polyfill") m.censor = require("./util/censor") module.exports = m diff --git a/mithril.js b/mithril.js index eb9306d1..1382c4b2 100644 --- a/mithril.js +++ b/mithril.js @@ -159,131 +159,7 @@ hyperscript.fragment = function() { vnode2.children = Vnode.normalizeChildren(vnode2.children) return vnode2 } -/* global window */ -/** @constructor */ -var PromisePolyfill = function(executor) { - if (!(this instanceof PromisePolyfill)) throw new Error("Promise must be called with 'new'.") - if (typeof executor !== "function") throw new TypeError("executor must be a function.") - var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false) - var instance = self._instance = {resolvers: resolvers, rejectors: rejectors} - var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout - function handler(list, shouldAbsorb) { - return function execute(value) { - var then - try { - if (shouldAbsorb && value != null && (typeof value === "object" || typeof value === "function") && typeof (then = value.then) === "function") { - if (value === self) throw new TypeError("Promise can't be resolved with itself.") - executeOnce(then.bind(value)) - } - else { - callAsync(function() { - if (!shouldAbsorb && list.length === 0) console.error("Possible unhandled promise rejection:", value) - for (var i = 0; i < list.length; i++) list[i](value) - resolvers.length = 0, rejectors.length = 0 - instance.state = shouldAbsorb - instance.retry = function() {execute(value)} - }) - } - } - catch (e) { - rejectCurrent(e) - } - } - } - function executeOnce(then) { - var runs = 0 - function run(fn) { - return function(value) { - if (runs++ > 0) return - fn(value) - } - } - var onerror = run(rejectCurrent) - try {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)} - } - executeOnce(executor) -} -PromisePolyfill.prototype.then = function(onFulfilled, onRejection) { - var self = this, instance = self._instance - function handle(callback, list, next, state) { - list.push(function(value) { - if (typeof callback !== "function") next(value) - else try {resolveNext(callback(value))} catch (e) {if (rejectNext) rejectNext(e)} - }) - if (typeof instance.retry === "function" && state === instance.state) instance.retry() - } - var resolveNext, rejectNext - var promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject}) - handle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false) - return promise -} -PromisePolyfill.prototype.catch = function(onRejection) { - return this.then(null, onRejection) -} -PromisePolyfill.prototype.finally = function(callback) { - return this.then( - function(value) { - return PromisePolyfill.resolve(callback()).then(function() { - return value - }) - }, - function(reason) { - return PromisePolyfill.resolve(callback()).then(function() { - return PromisePolyfill.reject(reason); - }) - } - ) -} -PromisePolyfill.resolve = function(value) { - if (value instanceof PromisePolyfill) return value - return new PromisePolyfill(function(resolve) {resolve(value)}) -} -PromisePolyfill.reject = function(value) { - return new PromisePolyfill(function(resolve, reject) {reject(value)}) -} -PromisePolyfill.all = function(list) { - return new PromisePolyfill(function(resolve, reject) { - var total = list.length, count = 0, values = [] - if (list.length === 0) resolve([]) - else for (var i = 0; i < list.length; i++) { - (function(i) { - function consume(value) { - count++ - values[i] = value - if (count === total) resolve(values) - } - if (list[i] != null && (typeof list[i] === "object" || typeof list[i] === "function") && typeof list[i].then === "function") { - list[i].then(consume, reject) - } - else consume(list[i]) - })(i) - } - }) -} -PromisePolyfill.race = function(list) { - return new PromisePolyfill(function(resolve, reject) { - for (var i = 0; i < list.length; i++) { - list[i].then(resolve, reject) - } - }) -} -if (typeof window !== "undefined") { - if (typeof window.Promise === "undefined") { - window.Promise = PromisePolyfill - } else if (!window.Promise.prototype.finally) { - window.Promise.prototype.finally = PromisePolyfill.prototype.finally - } - var PromisePolyfill = window.Promise -} else if (typeof global !== "undefined") { - if (typeof global.Promise === "undefined") { - global.Promise = PromisePolyfill - } else if (!global.Promise.prototype.finally) { - global.Promise.prototype.finally = PromisePolyfill.prototype.finally - } - var PromisePolyfill = global.Promise -} else { -} -var _13 = function($window) { +var _11 = function($window) { var $doc = $window && $window.document var currentRedraw var nameSpace = { @@ -480,7 +356,7 @@ var _13 = function($window) { // 3) remove the nodes present in the old list, but absent in the new one // 4) figure out what nodes in 1) to move in order to minimize the DOM operations. // - // To achieve 1) one can create a dictionary of keys => index (for the old list), then0 iterate + // To achieve 1) one can create a dictionary of keys => index (for the old list), then iterate // over the new list and for each new vnode3, find the corresponding vnode3 in the old list using // the map. // 2) is achieved in the same step: if a new node has no corresponding entry in the map, it is new @@ -526,7 +402,7 @@ var _13 = function($window) { // // In most scenarios `updateNode()` and `createNode()` perform the DOM operations. However, // this is not the case if the node moved (second and fourth part of the diff algo). We move - // the old DOM nodes before updateNode runs0 because it enables us to use the cached `nextSibling` + // the old DOM nodes before updateNode runs because it enables us to use the cached `nextSibling` // variable rather than fetching it using `getNextSibling()`. // // The fourth part of the diff currently inserts nodes unconditionally, leading to issues @@ -811,7 +687,7 @@ var _13 = function($window) { } // This covers a really specific edge case: // - Parent node is keyed and contains child - // - Child is removed, returns unresolved promise0 in `onbeforeremove` + // - Child is removed, returns unresolved promise in `onbeforeremove` // - Parent node is moved in keyed diff // - Remaining children2 still need moved appropriately // @@ -1127,7 +1003,7 @@ var _13 = function($window) { // with a `handleEvent` method. // 3. The object does not inherit from `Object.prototype`, to avoid // any potential interference with that (e.g. setters). - // 4. The event name is remapped to the handler0 before calling it. + // 4. The event name is remapped to the handler before calling it. // 5. In function-based event handlers, `ev.target === this`. We replicate // that below. // 6. In function-based event handlers, `return false` prevents the default @@ -1138,10 +1014,10 @@ var _13 = function($window) { } EventDict.prototype = Object.create(null) EventDict.prototype.handleEvent = function (ev) { - var handler0 = this["on" + ev.type] + var handler = this["on" + ev.type] var result - if (typeof handler0 === "function") result = handler0.call(ev.currentTarget, ev) - else if (typeof handler0.handleEvent === "function") handler0.handleEvent(ev) + if (typeof handler === "function") result = handler.call(ev.currentTarget, ev) + else if (typeof handler.handleEvent === "function") handler.handleEvent(ev) if (this._ && ev.redraw !== false) (0, this._)() if (result === false) { ev.preventDefault() @@ -1229,8 +1105,8 @@ var _13 = function($window) { } } } -var render = _13(typeof window !== "undefined" ? window : null) -var _16 = function(render0, schedule, console) { +var render = _11(typeof window !== "undefined" ? window : null) +var _14 = function(render0, schedule, console) { var subscriptions = [] var pending = false var offset = -1 @@ -1268,7 +1144,7 @@ var _16 = function(render0, schedule, console) { } return {mount: mount, redraw: redraw} } -var mountRedraw0 = _16(render, typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : null, typeof console !== "undefined" ? console : null) +var mountRedraw0 = _14(render, typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : null, typeof console !== "undefined" ? console : null) var buildQueryString = function(object) { if (Object.prototype.toString.call(object) !== "[object Object]") return "" var args = [] @@ -1330,7 +1206,7 @@ var buildPathname = function(template, params) { if (newHashIndex >= 0) result0 += (hashIndex < 0 ? "" : "&") + resolved.slice(newHashIndex) return result0 } -var _19 = function($window, Promise, oncompletion) { +var _17 = function($window, oncompletion) { var callbackCount = 0 function PromiseProxy(executor) { return new Promise(executor) @@ -1344,7 +1220,7 @@ var _19 = function($window, Promise, oncompletion) { return function(url, args) { if (typeof url !== "string") { args = url; url = url.url } else if (args == null) args = {} - var promise1 = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve, reject) { factory(buildPathname(url, args.params), args, function (data) { if (typeof args.type === "function") { if (Array.isArray(data)) { @@ -1357,32 +1233,32 @@ var _19 = function($window, Promise, oncompletion) { resolve(data) }, reject) }) - if (args.background === true) return promise1 + if (args.background === true) return promise var count = 0 function complete() { if (--count === 0 && typeof oncompletion === "function") oncompletion() } - return wrap(promise1) - function wrap(promise1) { - var then1 = promise1.then + return wrap(promise) + function wrap(promise) { + var then = promise.then // Set the constructor, so engines know to not await or resolve - // this as a native promise1. At the time of writing, this is0 + // this as a native promise. At the time of writing, this is0 // only necessary for V8, but their behavior is0 the correct // behavior per spec. See this spec issue for more details: // https://github.com/tc39/ecma262/issues/1577. Also, see the // corresponding comment in `request0/tests/test-request0.js` for // a bit more background on the issue at hand. - promise1.constructor = PromiseProxy - promise1.then = function() { + promise.constructor = PromiseProxy + promise.then = function() { count++ - var next0 = then1.apply(promise1, arguments) + var next0 = then.apply(promise, arguments) next0.then(complete, function(e) { complete() if (count === 0) throw e }) return wrap(next0) } - return promise1 + return promise } } } @@ -1466,9 +1342,9 @@ var _19 = function($window, Promise, oncompletion) { } if (xhr.status === 0) { // Use setTimeout to push this code block onto the event queue - // This allows `xhr.ontimeout` to run0 in the case that there is0 a timeout + // This allows `xhr.ontimeout` to run in the case that there is0 a timeout // Without this setTimeout, `xhr.ontimeout` doesn't have a chance to reject - // as `xhr.onreadystatechange` will run0 before it + // as `xhr.onreadystatechange` will run before it setTimeout(function() { if (isTimeout) return completeErrorResponse() @@ -1523,7 +1399,7 @@ var _19 = function($window, Promise, oncompletion) { }), } } -var request = _19(typeof window !== "undefined" ? window : null, PromisePolyfill, mountRedraw0.redraw) +var request = _17(typeof window !== "undefined" ? window : null, mountRedraw0.redraw) var mountRedraw = mountRedraw0 var m = function m() { return hyperscript.apply(this, arguments) } m.m = hyperscript @@ -1532,7 +1408,6 @@ m.fragment = hyperscript.fragment m.Fragment = "[" m.mount = mountRedraw.mount var m6 = hyperscript -var Promise = PromisePolyfill function decodeURIComponentSave0(str) { try { return decodeURIComponent(str) @@ -1588,7 +1463,6 @@ var parsePathname = function(url) { if (!path1) path1 = "/" else { if (path1[0] !== "/") path1 = "/" + path1 - if (path1.length > 1 && path1[path1.length - 1] === "/") path1 = path1.slice(0, -1) } return { path: path1, @@ -1685,8 +1559,8 @@ function decodeURIComponentSave(component) { return component } } -var _28 = function($window, mountRedraw00) { - var callAsync0 = $window == null +var _26 = function($window, mountRedraw00) { + var callAsync = $window == null // In case Mithril.js' loaded globally without the DOM, let's not break ? null : typeof $window.setImmediate === "function" ? $window.setImmediate : $window.setTimeout @@ -1794,7 +1668,7 @@ var _28 = function($window, mountRedraw00) { // TODO: just do `mountRedraw00.redraw1()` here and elide the timer // dependency. Note that this will muck with tests a *lot*, so it's // not as easy of a change as it sounds. - callAsync0(resolveRoute) + callAsync(resolveRoute) } } function setPath(path0, data, options) { @@ -1891,7 +1765,7 @@ var _28 = function($window, mountRedraw00) { // Adapted from React Router's implementation: // https://github.com/ReactTraining/react-router/blob/520a0acd48ae1b066eb0b07d6d4d1790a1d02482/packages/react-router-dom/modules/Link.js // - // Try to be flexible and intuitive in how we handle0 links. + // Try to be flexible and intuitive in how we handle links. // Fun fact: links aren't as obvious to get right as you // would expect. There's a lot more valid ways to click a // link than this, and one might want to not simply click a @@ -1902,7 +1776,7 @@ var _28 = function($window, mountRedraw00) { result1 !== false && !e.defaultPrevented && // Ignore everything but left clicks (e.button === 0 || e.which === 0 || e.which === 1) && - // Let the browser handle0 `target=_blank`, etc. + // Let the browser handle `target=_blank`, etc. (!e.currentTarget.target || e.currentTarget.target === "_self") && // No modifier keys !e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey @@ -1921,7 +1795,7 @@ var _28 = function($window, mountRedraw00) { } return route } -m.route = _28(typeof window !== "undefined" ? window : null, mountRedraw) +m.route = _26(typeof window !== "undefined" ? window : null, mountRedraw) m.render = render m.redraw = mountRedraw.redraw m.request = request.request @@ -1931,7 +1805,6 @@ m.buildQueryString = buildQueryString m.parsePathname = parsePathname m.buildPathname = buildPathname m.vnode = Vnode -m.PromisePolyfill = PromisePolyfill m.censor = censor if (typeof module !== "undefined") module["exports"] = m else window.m = m diff --git a/mithril.min.js b/mithril.min.js index 4da413e8..aba73626 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e,t,n,r,o,i){return{tag:e,key:t,attrs:n,children:r,text:o,dom:i,domSize:void 0,state:void 0,events:void 0,instance:void 0}}e.normalize=function(t){return Array.isArray(t)?e("[",void 0,void 0,e.normalizeChildren(t),void 0,void 0):null==t||"boolean"==typeof t?null:"object"==typeof t?t:e("#",void 0,void 0,String(t),void 0,void 0)},e.normalizeChildren=function(t){var n=[];if(t.length){for(var r=null!=t[0]&&null!=t[0].key,o=1;o0&&(l.className=i.join(" ")),o[e]={tag:n,attrs:l}}(l),a):(a.tag=l,a)}if(l.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},l.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n},(a=function(e){if(!(this instanceof a))throw new Error("Promise must be called with 'new'.");if("function"!=typeof e)throw new TypeError("executor must be a function.");var t=this,n=[],r=[],o=s(n,!0),i=s(r,!1),l=t._instance={resolvers:n,rejectors:r},u="function"==typeof setImmediate?setImmediate:setTimeout;function s(e,o){return function a(s){var f;try{if(!o||null==s||"object"!=typeof s&&"function"!=typeof s||"function"!=typeof(f=s.then))u((function(){o||0!==e.length||console.error("Possible unhandled promise rejection:",s);for(var t=0;t0||e(n)}}var r=n(i);try{e(n(o),r)}catch(e){r(e)}}c(e)}).prototype.then=function(e,t){var n,r,o=this._instance;function i(e,t,i,l){t.push((function(t){if("function"!=typeof e)i(t);else try{n(e(t))}catch(e){r&&r(e)}})),"function"==typeof o.retry&&l===o.state&&o.retry()}var l=new a((function(e,t){n=e,r=t}));return i(e,o.resolvers,n,!0),i(t,o.rejectors,r,!1),l},a.prototype.catch=function(e){return this.then(null,e)},a.prototype.finally=function(e){return this.then((function(t){return a.resolve(e()).then((function(){return t}))}),(function(t){return a.resolve(e()).then((function(){return a.reject(t)}))}))},a.resolve=function(e){return e instanceof a?e:new a((function(t){t(e)}))},a.reject=function(e){return new a((function(t,n){n(e)}))},a.all=function(e){return new a((function(t,n){var r=e.length,o=0,i=[];if(0===e.length)t([]);else for(var l=0;l'+t.children+"",l=l.firstChild):l.innerHTML=t.children,t.dom=l.firstChild,t.domSize=l.childNodes.length,t.instance=[];for(var a,u=r.createDocumentFragment();a=l.firstChild;)t.instance.push(a),u.appendChild(a);w(e,u,o)}function p(e,t,n,r,o,i){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)s(e,n,0,n.length,r,o,i);else if(null==n||0===n.length)k(e,t,0,t.length);else{var l=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,u=0,f=0;if(!l)for(;f=f&&j>=u&&(w=t[E],b=n[j],w.key===b.key);)w!==b&&h(e,w,b,r,o,i),null!=b.dom&&(o=b.dom),E--,j--;for(;E>=f&&j>=u&&(d=t[f],p=n[u],d.key===p.key);)f++,u++,d!==p&&h(e,d,p,r,y(t,f,o),i);for(;E>=f&&j>=u&&u!==j&&d.key===b.key&&w.key===p.key;)g(e,w,S=y(t,f,o)),w!==p&&h(e,w,p,r,S,i),++u<=--j&&g(e,d,o),d!==b&&h(e,d,b,r,o,i),null!=b.dom&&(o=b.dom),f++,w=t[--E],b=n[j],d=t[f],p=n[u];for(;E>=f&&j>=u&&w.key===b.key;)w!==b&&h(e,w,b,r,o,i),null!=b.dom&&(o=b.dom),j--,w=t[--E],b=n[j];if(u>j)k(e,t,f,E+1);else if(f>E)s(e,n,u,j+1,r,o,i);else{var C,z,A=o,T=j-u+1,N=new Array(T),O=0,P=0,I=2147483647,$=0;for(P=0;P=u;P--){null==C&&(C=v(t,f,E+1));var L=C[(b=n[P]).key];null!=L&&(I=L>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(m[o]=t[n-1]),t[n]=o)}}n=t.length,r=t[n-1];for(;n-- >0;)t[n]=r,r=m[r];return m.length=0,t}(N)).length-1,P=j;P>=u;P--)p=n[P],-1===N[P-u]?c(e,p,r,i,o):z[O]===P-u?O--:g(e,p,o),null!=p.dom&&(o=n[P].dom);else for(P=j;P>=u;P--)p=n[P],-1===N[P-u]&&c(e,p,r,i,o),null!=p.dom&&(o=n[P].dom)}}else{var R=t.lengthR&&k(e,t,u,t.length),n.length>R&&s(e,n,u,n.length,r,o,i)}}}function h(t,n,r,o,l,u){var s=n.tag;if(s===r.tag){if(r.state=n.state,r.events=n.events,function(e,t){do{var n;if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate)if(void 0!==(n=a.call(e.attrs.onbeforeupdate,e,t))&&!n)break;if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate)if(void 0!==(n=a.call(e.state.onbeforeupdate,e,t))&&!n)break;return!1}while(0);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}(r,n))return;if("string"==typeof s)switch(null!=r.attrs&&D(r.attrs,r,o),s){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(S(e,t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize,n.instance=t.instance)}(t,n,r,u,l);break;case"[":!function(e,t,n,r,o,i){p(e,t.children,n.children,r,o,i);var l=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var N,O=/[A-Z]/g;function P(e){return"-"+e.toLowerCase()}function I(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(O,P)}function $(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n){null!=(o=n[r])&&e.style.setProperty(I(r),String(o))}else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(I(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(I(r))}}function L(){this._=n}function R(e,t,r){if(null!=e.events){if(e.events._=n,e.events[t]===r)return;null==r||"function"!=typeof r&&"object"!=typeof r?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}else null==r||"function"!=typeof r&&"object"!=typeof r||(e.events=new L,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}function _(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function D(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return L.prototype=Object.create(null),L.prototype.handleEvent=function(e){var t,n=this["on"+e.type];"function"==typeof n?t=n.call(e.currentTarget,e):"function"==typeof n.handleEvent&&n.handleEvent(e),this._&&!1!==e.redraw&&(0,this._)(),!1===t&&(e.preventDefault(),e.stopPropagation())},function(t,r,o){if(!t)throw new TypeError("DOM element being rendered to does not exist.");if(null!=N&&t.contains(N))throw new TypeError("Node is currently being rendered to and thus is locked.");var i=n,l=N,a=[],s=u(),c=t.namespaceURI;N=t,n="function"==typeof o?o:void 0;try{null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]),p(t,t.vnodes,r,a,null,"http://www.w3.org/1999/xhtml"===c?void 0:c),t.vnodes=r,null!=s&&u()!==s&&"function"==typeof s.focus&&s.focus();for(var f=0;f=0&&(o.splice(i,2),i<=l&&(l-=2),t(n,[])),null!=r&&(o.push(n,r),t(n,e(r),u))},redraw:u}}(u,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console?console:null),c=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(v+=e.slice(n,o)),s>=0&&(v+=(n<0?"?":"&")+u.slice(s,p));var m=c(a);return m&&(v+=(n<0&&s<0?"?":"&")+m),r>=0&&(v+=e.slice(r)),d>=0&&(v+=(r<0?"":"&")+u.slice(d)),v},p=function(e,t,r){var o=0;function i(e){return new t(e)}function l(e){return function(n,o){"string"!=typeof n?(o=n,n=n.url):null==o&&(o={});var l=new t((function(t,r){e(d(n,o.params),o,(function(e){if("function"==typeof o.type)if(Array.isArray(e))for(var n=0;n=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===f){if(!e.target.responseType&&"function"!=typeof r.extract)try{a=JSON.parse(e.target.responseText)}catch(e){a=null}}else f&&"text"!==f||null==a&&(a=e.target.responseText);if("function"==typeof r.extract?(a=r.extract(e.target,r),l=!0):"function"==typeof r.deserialize&&(a=r.deserialize(a)),l)o(a);else{var u=function(){try{n=e.target.responseText}catch(e){n=a}var t=new Error(n);t.code=e.target.status,t.response=a,i(t)};0===d.status?setTimeout((function(){h||u()})):u()}}catch(e){i(e)}},d.ontimeout=function(e){h=!0;var t=new Error("Request timed out");t.code=e.target.status,i(t)},"function"==typeof r.config&&(d=r.config(d,r,t)||d)!==v&&(l=d.abort,d.abort=function(){p=!0,l.call(this)}),null==s?d.send():"function"==typeof r.serialize?d.send(r.serialize(s)):s instanceof e.FormData||s instanceof e.URLSearchParams?d.send(s):d.send(JSON.stringify(s))})),jsonp:l((function(t,n,r,i){var l=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+o++,a=e.document.createElement("script");e[l]=function(t){delete e[l],a.parentNode.removeChild(a),r(t)},a.onerror=function(){delete e[l],a.parentNode.removeChild(a),i(new Error("JSONP request failed"))},a.src=t+(t.indexOf("?")<0?"?":"&")+encodeURIComponent(n.callbackKey||"callback")+"="+encodeURIComponent(l),e.document.documentElement.appendChild(a)}))}}("undefined"!=typeof window?window:null,a,s.redraw),h=s,v=function(){return l.apply(this,arguments)};v.m=l,v.trust=l.trust,v.fragment=l.fragment,v.Fragment="[",v.mount=h.mount;var m=l,y=a;function g(e){try{return decodeURIComponent(e)}catch(t){return e}}var w=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},o=0;o-1&&u.pop();for(var c=0;c1&&"/"===i[i.length-1]&&(i=i.slice(0,-1))):i="/",{path:i,params:t<0?{}:w(e.slice(t+1,r))}},k=function(e){var t=b(e),n=Object.keys(t.params),r=[],o=new RegExp("^"+t.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,(function(e,t,n){return null==t?"\\"+e:(r.push({k:t,r:"..."===n}),"..."===n?"(.*)":"."===n?"([^/]+)\\.":"([^/]+)"+(n||""))}))+"$");return function(e){for(var i=0;i0&&(i.className=l.join(" ")),o[e]={tag:n,attrs:i}}(i),a):(a.tag=i,a)}i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n};var a=function(t){var n,r=t&&t.document,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function l(e){return e.attrs&&e.attrs.xmlns||o[e.tag]}function i(e,t){if(e.state!==t)throw new Error("'vnode.state' must not be modified.")}function a(e){var t=e.state;try{return this.apply(t,arguments)}finally{i(e,t)}}function u(){try{return r.activeElement}catch(e){return null}}function s(e,t,n,r,o,l,i){for(var a=n;a'+t.children+"",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length,t.instance=[];for(var a,u=r.createDocumentFragment();a=i.firstChild;)t.instance.push(a),u.appendChild(a);w(e,u,o)}function p(e,t,n,r,o,l){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)s(e,n,0,n.length,r,o,l);else if(null==n||0===n.length)k(e,t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,u=0,f=0;if(!i)for(;f=f&&C>=u&&(w=t[E],b=n[C],w.key===b.key);)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),E--,C--;for(;E>=f&&C>=u&&(d=t[f],p=n[u],d.key===p.key);)f++,u++,d!==p&&h(e,d,p,r,y(t,f,o),l);for(;E>=f&&C>=u&&u!==C&&d.key===b.key&&w.key===p.key;)g(e,w,S=y(t,f,o)),w!==p&&h(e,w,p,r,S,l),++u<=--C&&g(e,d,o),d!==b&&h(e,d,b,r,o,l),null!=b.dom&&(o=b.dom),f++,w=t[--E],b=n[C],d=t[f],p=n[u];for(;E>=f&&C>=u&&w.key===b.key;)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),C--,w=t[--E],b=n[C];if(u>C)k(e,t,f,E+1);else if(f>E)s(e,n,u,C+1,r,o,l);else{var j,z,A=o,N=C-u+1,O=new Array(N),T=0,$=0,L=2147483647,I=0;for($=0;$=u;$--){null==j&&(j=m(t,f,E+1));var R=j[(b=n[$]).key];null!=R&&(L=R>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(v[o]=t[n-1]),t[n]=o)}}n=t.length,r=t[n-1];for(;n-- >0;)t[n]=r,r=v[r];return v.length=0,t}(O)).length-1,$=C;$>=u;$--)p=n[$],-1===O[$-u]?c(e,p,r,l,o):z[T]===$-u?T--:g(e,p,o),null!=p.dom&&(o=n[$].dom);else for($=C;$>=u;$--)p=n[$],-1===O[$-u]&&c(e,p,r,l,o),null!=p.dom&&(o=n[$].dom)}}else{var P=t.lengthP&&k(e,t,u,t.length),n.length>P&&s(e,n,u,n.length,r,o,l)}}}function h(t,n,r,o,i,u){var s=n.tag;if(s===r.tag){if(r.state=n.state,r.events=n.events,function(e,t){do{var n;if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate)if(void 0!==(n=a.call(e.attrs.onbeforeupdate,e,t))&&!n)break;if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate)if(void 0!==(n=a.call(e.state.onbeforeupdate,e,t))&&!n)break;return!1}while(0);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}(r,n))return;if("string"==typeof s)switch(null!=r.attrs&&D(r.attrs,r,o),s){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(S(e,t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize,n.instance=t.instance)}(t,n,r,u,i);break;case"[":!function(e,t,n,r,o,l){p(e,t.children,n.children,r,o,l);var i=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var O,T=/[A-Z]/g;function $(e){return"-"+e.toLowerCase()}function L(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(T,$)}function I(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n){null!=(o=n[r])&&e.style.setProperty(L(r),String(o))}else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(L(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(L(r))}}function R(){this._=n}function P(e,t,r){if(null!=e.events){if(e.events._=n,e.events[t]===r)return;null==r||"function"!=typeof r&&"object"!=typeof r?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}else null==r||"function"!=typeof r&&"object"!=typeof r||(e.events=new R,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}function _(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function D(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return R.prototype=Object.create(null),R.prototype.handleEvent=function(e){var t,n=this["on"+e.type];"function"==typeof n?t=n.call(e.currentTarget,e):"function"==typeof n.handleEvent&&n.handleEvent(e),this._&&!1!==e.redraw&&(0,this._)(),!1===t&&(e.preventDefault(),e.stopPropagation())},function(t,r,o){if(!t)throw new TypeError("DOM element being rendered to does not exist.");if(null!=O&&t.contains(O))throw new TypeError("Node is currently being rendered to and thus is locked.");var l=n,i=O,a=[],s=u(),c=t.namespaceURI;O=t,n="function"==typeof o?o:void 0;try{null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]),p(t,t.vnodes,r,a,null,"http://www.w3.org/1999/xhtml"===c?void 0:c),t.vnodes=r,null!=s&&u()!==s&&"function"==typeof s.focus&&s.focus();for(var f=0;f=0&&(o.splice(l,2),l<=i&&(i-=2),t(n,[])),null!=r&&(o.push(n,r),t(n,e(r),u))},redraw:u}}(a,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console?console:null),s=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(m+=e.slice(n,o)),f>=0&&(m+=(n<0?"?":"&")+u.slice(f,p));var v=s(a);return v&&(m+=(n<0&&f<0?"?":"&")+v),r>=0&&(m+=e.slice(r)),d>=0&&(m+=(r<0?"":"&")+u.slice(d)),m},d=function(e,t){var r=0;function o(e){return new Promise(e)}function l(e){return function(n,r){"string"!=typeof n?(r=n,n=n.url):null==r&&(r={});var l=new Promise((function(t,o){e(f(n,r.params),r,(function(e){if("function"==typeof r.type)if(Array.isArray(e))for(var n=0;n=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===f){if(!e.target.responseType&&"function"!=typeof r.extract)try{a=JSON.parse(e.target.responseText)}catch(e){a=null}}else f&&"text"!==f||null==a&&(a=e.target.responseText);if("function"==typeof r.extract?(a=r.extract(e.target,r),i=!0):"function"==typeof r.deserialize&&(a=r.deserialize(a)),i)o(a);else{var u=function(){try{n=e.target.responseText}catch(e){n=a}var t=new Error(n);t.code=e.target.status,t.response=a,l(t)};0===d.status?setTimeout((function(){h||u()})):u()}}catch(e){l(e)}},d.ontimeout=function(e){h=!0;var t=new Error("Request timed out");t.code=e.target.status,l(t)},"function"==typeof r.config&&(d=r.config(d,r,t)||d)!==m&&(a=d.abort,d.abort=function(){p=!0,a.call(this)}),null==s?d.send():"function"==typeof r.serialize?d.send(r.serialize(s)):s instanceof e.FormData||s instanceof e.URLSearchParams?d.send(s):d.send(JSON.stringify(s))})),jsonp:l((function(t,n,o,l){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+r++,a=e.document.createElement("script");e[i]=function(t){delete e[i],a.parentNode.removeChild(a),o(t)},a.onerror=function(){delete e[i],a.parentNode.removeChild(a),l(new Error("JSONP request failed"))},a.src=t+(t.indexOf("?")<0?"?":"&")+encodeURIComponent(n.callbackKey||"callback")+"="+encodeURIComponent(i),e.document.documentElement.appendChild(a)}))}}("undefined"!=typeof window?window:null,u.redraw),p=u,h=function(){return i.apply(this,arguments)};h.m=i,h.trust=i.trust,h.fragment=i.fragment,h.Fragment="[",h.mount=p.mount;var m=i;function v(e){try{return decodeURIComponent(e)}catch(t){return e}}var y=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},o=0;o-1&&u.pop();for(var c=0;c 0) return - fn(value) - } - } - var onerror = run(rejectCurrent) - try {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)} - } - - executeOnce(executor) -} -PromisePolyfill.prototype.then = function(onFulfilled, onRejection) { - var self = this, instance = self._instance - function handle(callback, list, next, state) { - list.push(function(value) { - if (typeof callback !== "function") next(value) - else try {resolveNext(callback(value))} catch (e) {if (rejectNext) rejectNext(e)} - }) - if (typeof instance.retry === "function" && state === instance.state) instance.retry() - } - var resolveNext, rejectNext - var promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject}) - handle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false) - return promise -} -PromisePolyfill.prototype.catch = function(onRejection) { - return this.then(null, onRejection) -} -PromisePolyfill.prototype.finally = function(callback) { - return this.then( - function(value) { - return PromisePolyfill.resolve(callback()).then(function() { - return value - }) - }, - function(reason) { - return PromisePolyfill.resolve(callback()).then(function() { - return PromisePolyfill.reject(reason); - }) - } - ) -} -PromisePolyfill.resolve = function(value) { - if (value instanceof PromisePolyfill) return value - return new PromisePolyfill(function(resolve) {resolve(value)}) -} -PromisePolyfill.reject = function(value) { - return new PromisePolyfill(function(resolve, reject) {reject(value)}) -} -PromisePolyfill.all = function(list) { - return new PromisePolyfill(function(resolve, reject) { - var total = list.length, count = 0, values = [] - if (list.length === 0) resolve([]) - else for (var i = 0; i < list.length; i++) { - (function(i) { - function consume(value) { - count++ - values[i] = value - if (count === total) resolve(values) - } - if (list[i] != null && (typeof list[i] === "object" || typeof list[i] === "function") && typeof list[i].then === "function") { - list[i].then(consume, reject) - } - else consume(list[i]) - })(i) - } - }) -} -PromisePolyfill.race = function(list) { - return new PromisePolyfill(function(resolve, reject) { - for (var i = 0; i < list.length; i++) { - list[i].then(resolve, reject) - } - }) -} - -module.exports = PromisePolyfill diff --git a/promise/promise.js b/promise/promise.js deleted file mode 100644 index c206221b..00000000 --- a/promise/promise.js +++ /dev/null @@ -1,22 +0,0 @@ -/* global window */ -"use strict" - -var PromisePolyfill = require("./polyfill") - -if (typeof window !== "undefined") { - if (typeof window.Promise === "undefined") { - window.Promise = PromisePolyfill - } else if (!window.Promise.prototype.finally) { - window.Promise.prototype.finally = PromisePolyfill.prototype.finally - } - module.exports = window.Promise -} else if (typeof global !== "undefined") { - if (typeof global.Promise === "undefined") { - global.Promise = PromisePolyfill - } else if (!global.Promise.prototype.finally) { - global.Promise.prototype.finally = PromisePolyfill.prototype.finally - } - module.exports = global.Promise -} else { - module.exports = PromisePolyfill -} diff --git a/promise/tests/test-promise.js b/promise/tests/test-promise.js deleted file mode 100644 index 07d600e1..00000000 --- a/promise/tests/test-promise.js +++ /dev/null @@ -1,720 +0,0 @@ -/* global window */ -"use strict" - -var o, callAsync, Promise - -if (typeof require !== "undefined") { - /* eslint-disable global-require */ - callAsync = require("../../test-utils/callAsync") - o = require("ospec") - Promise = require("../../promise/polyfill") - /* eslint-enable global-require */ -} else { - callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout - o = window.o - Promise = window.PromisePolyfill -} - -o.spec("promise", function() { - o.spec("constructor", function() { - o("constructor throws if called without new", function(done) { - try {Promise(function() {})} catch(e) {done()} - }) - o("constructor throws if called without executor", function(done) { - try {new Promise()} catch(e) {done()} - }) - o("constructor has correct methods", function() { - o(typeof Promise.prototype.then).equals("function") - o(typeof Promise.prototype.catch).equals("function") - o(typeof Promise.prototype.finally).equals("function") - o(typeof Promise.resolve).equals("function") - o(typeof Promise.reject).equals("function") - o(typeof Promise.race).equals("function") - o(typeof Promise.all).equals("function") - }) - }) - o.spec("return value", function() { - o("static resolve returns promise", function() { - var promise = Promise.resolve() - - o(promise instanceof Promise).equals(true) - }) - o("static reject returns promise", function() { - var promise = Promise.reject() - promise.catch(function() {}) - - o(promise instanceof Promise).equals(true) - }) - o("static resolve with promise input returns same promise", function() { - var resolved = Promise.resolve(1) - var promise = Promise.resolve(resolved) - - o(promise).equals(resolved) - }) - o("then returns promise", function(done) { - var promise = Promise.resolve(1) - - promise.then(function(value) { - o(value).equals(1) - }).then(done) - }) - o("catch returns promise", function(done) { - var promise = Promise.reject(1) - - promise.catch(function(value) { - o(value).equals(1) - }).then(done) - }) - o("finally lets a fulfilled value pass though", function(done) { - var promise = Promise.resolve(1) - var spy = o.spy(function(){return 2}) - - promise.finally(spy).then(function(value){ - o(value).equals(1) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - o("finally lets a rejected reason pass though", function(done) { - var promise = Promise.reject(1) - var spy = o.spy(function(){return 2}) - - promise.finally(spy).catch(function(reason){ - o(reason).equals(1) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - o("finally overrrides a fulfilled value when it throws", function(done) { - var promise = Promise.resolve(1) - var spy = o.spy(function(){throw 2}) - - promise.finally(spy).catch(function(reason){ - o(reason).equals(2) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - o("finally overrrides a fulfilled value when it returns a rejected Promise", function(done) { - var promise = Promise.resolve(1) - var spy = o.spy(function(){return Promise.reject(2)}) - - promise.finally(spy).catch(function(reason){ - o(reason).equals(2) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - o("finally overrrides a rejected reason when it throws", function(done) { - var promise = Promise.reject(1) - var spy = o.spy(function(){throw 2}) - - promise.finally(spy).catch(function(reason){ - o(reason).equals(2) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - o("finally overrrides a rejected reason when it returns a rejected Promise", function(done) { - var promise = Promise.reject(1) - var spy = o.spy(function(){return Promise.reject(2)}) - - promise.finally(spy).catch(function(reason){ - o(reason).equals(2) - o(spy.callCount).equals(1) - o(spy.args.length).equals(0) - o(spy.this).equals(undefined) - done() - }) - }) - }) - o.spec("resolve", function() { - o("resolves once", function(done) { - var callCount = 0 - var promise = new Promise(function(resolve) { - resolve(1) - resolve(2) - callAsync(function() {resolve(3)}) - }) - - promise.then(function(value) { - callCount++ - - o(value).equals(1) - o(callCount).equals(1) - done() - }) - }) - o("does not reject after resolve", function(done) { - var promise = new Promise(function(resolve, reject) { - resolve(1) - reject(2) - callAsync(function() {reject(3)}) - }) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("resolves asynchronously", function(done) { - var state = 0 - - var promise = Promise.resolve() - - state = 1 - promise.then(function() { - o(state).equals(2) - done() - }) - state = 2 - }) - o("resolves via static method", function(done) { - var promise = Promise.resolve(1) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("resolves asynchronously via executor", function(done) { - var promise = new Promise(function(resolve) { - callAsync(function() {resolve(1)}) - }) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("downstreams correctly", function(done) { - var promise = Promise.resolve(1) - var a = promise.then(function(value) {return value + 1}) - var b = promise.then(function(value) {return value + 2}) - - a.then(function(aValue) { - b.then(function(bValue) { - o(aValue).equals(2) - o(bValue).equals(3) - done() - }) - }) - }) - o("cannot resolve to itself", function(done) { - var promise = new Promise(function(resolve) { - callAsync(function() {resolve(promise)}) - }) - - promise.then(null, function() { done() }) - }) - o("non-function onFulfilled is ignored", function(done) { - var promise = Promise.resolve(1) - - promise.then(null, null).then(function(value) { - o(value).equals(1) - done() - }) - }) - o("non-function onFulfilled with no second param is ignored", function(done) { - var promise = Promise.resolve(1) - - promise.then(null).then(function(value) { - o(value).equals(1) - done() - }) - }) - }) - o.spec("reject", function() { - o("rejects once", function(done) { - var callCount = 0 - var promise = new Promise(function(resolve, reject) { - reject(1) - reject(2) - callAsync(function() {reject(3)}) - }) - - promise.then(null, function(value) { - callCount++ - - o(value).equals(1) - o(callCount).equals(1) - done() - }) - }) - o("does not resolve after reject", function(done) { - var promise = new Promise(function(resolve, reject) { - reject(1) - resolve(2) - callAsync(function() {resolve(3)}) - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects asynchronously", function(done) { - var state = 0 - - var promise = Promise.reject() - - state = 1 - promise.then(null, function() { - o(state).equals(2) - done() - }) - state = 2 - }) - o("does not catch itself", function(done) { - var callCount = 0 - var promise = Promise.resolve().then(function() {throw 1}, function() {callCount++}) - - promise.then(null, function() { - o(callCount).equals(0) - done() - }) - }) - o("rejects via static method", function(done) { - var promise = Promise.reject(1) - - promise.then(null, function(value) { - o(value).equals(1) - return value - }).then(function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects synchronously via executor", function(done) { - var promise = new Promise(function(resolve, reject) { - reject(1) - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects asynchronously via executor", function(done) { - var promise = new Promise(function(resolve, reject) { - callAsync(function() {reject(1)}) - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects via executor on error", function(done) { - var promise = new Promise(function() { - throw 1 - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects on fulfillment error", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - throw 1 - }).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects on rejection error", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - throw 1 - }).then(null, function() { - throw 2 - }).then(null, function(value) { - o(value).equals(2) - done() - }) - }) - o("non-function onRejected is ignored", function(done) { - var promise = Promise.reject(1) - - promise.then(function() {}, null).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - }) - o.spec("promise absorption", function() { - o("absorbs resolved promise via static resolver", function(done) { - var promise = Promise.resolve(Promise.resolve(1)) - - promise.then(function(value) { - o(value).equals(1) - }).then(done) - }) - o("absorbs resolved promise in executor resolve", function(done) { - var promise = new Promise(function(resolve) { - var p = Promise.resolve(1) - resolve(p) - }) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs resolved promise on fulfillment", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - return Promise.resolve(1) - }).then(function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs rejected promise via static resolver", function(done) { - var promise = Promise.resolve(Promise.reject(1)) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs rejected promise in executor resolve", function(done) { - var promise = new Promise(function(resolve) { - resolve(Promise.reject(1)) - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs rejected promise on fulfillment", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - return Promise.reject(1) - }).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that resolves via static resolver", function(done) { - var pending = new Promise(function(resolve) { - setTimeout(function() {resolve(1)}, 10) - }) - var promise = Promise.resolve(pending) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that resolves in executor resolve", function(done) { - var pending = new Promise(function(resolve) { - setTimeout(function() {resolve(1)}, 10) - }) - var promise = new Promise(function(resolve) { - resolve(pending) - }) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that resolves on fulfillment", function(done) { - var pending = new Promise(function(resolve) { - setTimeout(function() {resolve(1)}, 10) - }) - var promise = Promise.resolve() - - promise.then(function() { - return pending - }).then(function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that rejects via static resolver", function(done) { - var pending = new Promise(function(resolve, reject) { - setTimeout(function() {reject(1)}, 10) - }) - var promise = Promise.resolve(pending) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that rejects in executor resolve", function(done) { - var pending = new Promise(function(resolve, reject) { - setTimeout(function() {reject(1)}, 10) - }) - var promise = new Promise(function(resolve) { - resolve(pending) - }) - - promise.then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("absorbs pending promise that rejects on fulfillment", function(done) { - var pending = new Promise(function(resolve, reject) { - setTimeout(function() {reject(1)}, 10) - }) - var promise = Promise.resolve() - - promise.then(function() { - return pending - }).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - o("triggers all branched rejection handlers upon rejection", function(done) { - var promise = Promise.reject() - var then = o.spy() - var catch1 = o.spy() - var catch2 = o.spy() - var catch3 = o.spy() - - promise.catch(catch1) - promise.then(then, catch2) - promise.then(then).catch(catch3) - - callAsync(function() { - callAsync(function() { - o(catch1.callCount).equals(1) - o(then.callCount).equals(0) - o(catch2.callCount).equals(1) - o(catch3.callCount).equals(1) - done() - }) - }) - }) - o("does not absorb resolved promise via static rejector", function(done) { - var promise = Promise.reject(Promise.resolve(1)) - - promise.then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("does not absorb rejected promise via static rejector", function(done) { - var rejected = Promise.reject(1) - rejected.catch(function() {}) - var promise = Promise.reject(rejected) - - promise.then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("does not absorb resolved promise in executor reject", function(done) { - var promise = new Promise(function(resolve, reject) { - reject(Promise.resolve(1)) - }) - - promise.then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("does not absorb rejected promise in executor reject", function(done) { - var promise = new Promise(function(resolve, reject) { - var rejected = Promise.reject(1) - rejected.catch(function() {}) - reject(rejected) - }) - - promise.then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("does not absorb resolved promise on fulfillment error", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - throw Promise.resolve(1) - }).then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("does not absorb rejected promise on fulfillment error", function(done) { - var promise = Promise.resolve() - - promise.then(function() { - var rejected = Promise.reject(1) - rejected.catch(function() {}) - throw rejected - }).then(null, function(value) { - o(value instanceof Promise).equals(true) - done() - }) - }) - o("promise stays pending if absorbed promise is pending", function(done) { - var promise = new Promise(function(resolve) {resolve()}) - var fulfilled = false, rejected = false - - promise.then(function() { - return new Promise(function() {}) - }).then(function() { - fulfilled = true - }, function() { - rejected = false - }) - - setTimeout(function() { - o(fulfilled).equals(false) - o(rejected).equals(false) - done() - }, 10) - }) - o("absorbs early resolved promise", function(done) { - var resolved = Promise.resolve(1) - var promise = new Promise(function(resolve) { - setTimeout(function() { - resolve(resolved) - }, 10) - }) - - promise.then(function(value) { - o(value).equals(1) - done() - }) - }) - }) - o.spec("race", function() { - o("resolves to first resolved", function(done) { - var a = Promise.resolve(1) - var b = new Promise(function(resolve) { - callAsync(function() {resolve(2)}) - }) - Promise.race([a, b]).then(function(value) { - o(value).equals(1) - done() - }) - }) - o("rejects to first rejected", function(done) { - var a = Promise.reject(1) - var b = new Promise(function(resolve, reject) { - callAsync(function() {reject(2)}) - }) - Promise.race([a, b]).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - }) - o.spec("all", function() { - o("resolves to array", function(done) { - var a = new Promise(function(resolve) { - callAsync(function() {resolve(1)}) - }) - var b = Promise.resolve(2) - Promise.all([a, b]).then(function(value) { - o(value).deepEquals([1, 2]) - done() - }) - }) - o("resolves empty array", function(done) { - Promise.all([]).then(function(value) { - o(value).deepEquals([]) - done() - }) - }) - o("resolves non-promise to itself", function(done) { - var a = new Promise(function(resolve) { - callAsync(function() {resolve(1)}) - }) - var b = Promise.resolve(2) - var c = 3 - Promise.all([a, b, c]).then(function(value) { - o(value).deepEquals([1, 2, 3]) - done() - }) - }) - o("rejects to first rejected", function(done) { - var a = Promise.reject(1) - var b = new Promise(function(resolve, reject) { - callAsync(function() {reject(2)}) - }) - Promise.all([a, b]).then(null, function(value) { - o(value).equals(1) - done() - }) - }) - }) - o.spec("A+ compliance", function() { - o("accesses then only once", function(done) { - var readCount = 0 - var promise = Promise.resolve(1).then(function() { - return Object.create(null, { - then: { - get: function () { - ++readCount - return function(onFulfilled) { - onFulfilled() - } - } - } - }) - }) - - promise.then(function() { - o(readCount).equals(1) - done() - }) - }) - o("works if thennable resolves twice", function(done) { - var promise = Promise.resolve({ - then: function(res) { - res({ - then: function(resolve) { - setTimeout(function() {resolve(2)}) - } - }) - res(1) - } - }) - - promise.then(function(value) { - o(value).equals(2) - done() - }) - }) - o("works if thennable resolves async rejection then throws", function(done) { - var promise = new Promise(function(res) { - res({ - then: function(resolve, reject) { - setTimeout(function() {reject(2)}) - } - }) - throw 3 - }) - - promise.then(null, function(value) { - o(value).equals(2) - done() - }) - }) - }) -}) diff --git a/promise/tests/test.html b/promise/tests/test.html deleted file mode 100644 index f56bdd12..00000000 --- a/promise/tests/test.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/render/tests/test-onbeforeremove.js b/render/tests/test-onbeforeremove.js index a46b829e..96a27b74 100644 --- a/render/tests/test-onbeforeremove.js +++ b/render/tests/test-onbeforeremove.js @@ -5,7 +5,6 @@ var callAsync = require("../../test-utils/callAsync") var components = require("../../test-utils/components") var domMock = require("../../test-utils/domMock") var vdom = require("../../render/render") -var Promise = require("../../promise/promise") var m = require("../../render/hyperscript") var fragment = require("../../render/fragment") diff --git a/request.js b/request.js index 49a3968c..740119bf 100644 --- a/request.js +++ b/request.js @@ -1,6 +1,5 @@ "use strict" -var PromisePolyfill = require("./promise/promise") var mountRedraw = require("./mount-redraw") -module.exports = require("./request/request")(typeof window !== "undefined" ? window : null, PromisePolyfill, mountRedraw.redraw) +module.exports = require("./request/request")(typeof window !== "undefined" ? window : null, mountRedraw.redraw) diff --git a/request/request.js b/request/request.js index 54fae64d..c9ed1719 100644 --- a/request/request.js +++ b/request/request.js @@ -3,7 +3,7 @@ var buildPathname = require("../pathname/build") var hasOwn = require("../util/hasOwn") -module.exports = function($window, Promise, oncompletion) { +module.exports = function($window, oncompletion) { var callbackCount = 0 function PromiseProxy(executor) { diff --git a/request/tests/test-jsonp.js b/request/tests/test-jsonp.js index a52c67a8..f4eca4ab 100644 --- a/request/tests/test-jsonp.js +++ b/request/tests/test-jsonp.js @@ -3,7 +3,6 @@ var o = require("ospec") var xhrMock = require("../../test-utils/xhrMock") var Request = require("../../request/request") -var PromisePolyfill = require("../../promise/promise") var parseQueryString = require("../../querystring/parse") o.spec("jsonp", function() { @@ -11,7 +10,7 @@ o.spec("jsonp", function() { o.beforeEach(function() { mock = xhrMock() complete = o.spy() - jsonp = Request(mock, PromisePolyfill, complete).jsonp + jsonp = Request(mock, complete).jsonp }) o("works", function(done) { diff --git a/request/tests/test-request.js b/request/tests/test-request.js index b794a525..a5e5d980 100644 --- a/request/tests/test-request.js +++ b/request/tests/test-request.js @@ -4,14 +4,13 @@ var o = require("ospec") var callAsync = require("../../test-utils/callAsync") var xhrMock = require("../../test-utils/xhrMock") var Request = require("../../request/request") -var PromisePolyfill = require("../../promise/promise") o.spec("request", function() { var mock, request, complete o.beforeEach(function() { mock = xhrMock() complete = o.spy() - request = Request(mock, PromisePolyfill, complete).request + request = Request(mock, complete).request }) o.spec("success", function() { @@ -894,7 +893,7 @@ o.spec("request", function() { // if you use the polyfill, as it's based on `setImmediate` (falling // back to `setTimeout`), and promise microtasks are run at higher // priority than either of those. - request = Request(mock, Promise, complete).request + request = Request(mock, complete).request mock.$defineRoutes({ "GET /item": function() { return {status: 200, responseText: "[]"}