Commit a1ab9293 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Update RSVP and RenderJS to latest version

parent 0c29519c
This diff is collapsed.
...@@ -60,7 +60,7 @@ define("rsvp/all", ...@@ -60,7 +60,7 @@ define("rsvp/all",
} }
} }
return new Promise(function(resolve, reject, notify) { return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length, var results = [], remaining = promises.length,
promise, remaining_count = promises.length - expected_count; promise, remaining_count = promises.length - expected_count;
...@@ -90,12 +90,6 @@ define("rsvp/all", ...@@ -90,12 +90,6 @@ define("rsvp/all",
} }
} }
function notifier(index) {
return function(value) {
notify({"index": index, "value": value});
};
}
function cancelAll(rejectionValue) { function cancelAll(rejectionValue) {
reject(rejectionValue); reject(rejectionValue);
canceller(); canceller();
...@@ -105,7 +99,7 @@ define("rsvp/all", ...@@ -105,7 +99,7 @@ define("rsvp/all",
promise = promises[i]; promise = promises[i];
if (promise && typeof promise.then === 'function') { if (promise && typeof promise.then === 'function') {
promise.then(resolver(i), cancelAll, notifier(i)); promise.then(resolver(i), cancelAll);
} else { } else {
resolveAll(i, promise); resolveAll(i, promise);
} }
...@@ -135,6 +129,29 @@ define("rsvp/async", ...@@ -135,6 +129,29 @@ define("rsvp/async",
var async; var async;
var local = (typeof global !== 'undefined') ? global : this; var local = (typeof global !== 'undefined') ? global : this;
function checkNativePromise() {
if (typeof Promise === "function" &&
typeof Promise.resolve === "function") {
try {
/* global Promise */
var promise = new Promise(function(){});
if ({}.toString.call(promise) === "[object Promise]") {
return true;
}
} catch (e) {}
}
return false;
}
function useNativePromise() {
var nativePromise = Promise.resolve();
return function(callback, arg) {
nativePromise.then(function () {
callback(arg);
});
};
}
// old node // old node
function useNextTick() { function useNextTick() {
return function(callback, arg) { return function(callback, arg) {
...@@ -190,7 +207,9 @@ define("rsvp/async", ...@@ -190,7 +207,9 @@ define("rsvp/async",
}; };
} }
if (typeof setImmediate === 'function') { if (checkNativePromise()) {
async = useNativePromise();
} else if (typeof setImmediate === 'function') {
async = useSetImmediate(); async = useSetImmediate();
} else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
async = useNextTick(); async = useNextTick();
...@@ -360,10 +379,10 @@ define("rsvp/events", ...@@ -360,10 +379,10 @@ define("rsvp/events",
__exports__.EventTarget = EventTarget; __exports__.EventTarget = EventTarget;
}); });
define("rsvp/hash", define("rsvp/hash",
["rsvp/defer","exports"], ["rsvp/promise","exports"],
function(__dependency1__, __exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var defer = __dependency1__.defer; var Promise = __dependency1__.Promise;
function size(object) { function size(object) {
var s = 0; var s = 0;
...@@ -376,38 +395,61 @@ define("rsvp/hash", ...@@ -376,38 +395,61 @@ define("rsvp/hash",
} }
function hash(promises) { function hash(promises) {
var results = {}, deferred = defer(), remaining = size(promises);
function canceller() {
var promise,
key;
for (key in promises) {
if (promises.hasOwnProperty(key)) {
promise = promises[key];
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
}
}
}
}
return new Promise(function(resolve, reject) {
var results = {}, remaining = size(promises),
promise;
if (remaining === 0) { if (remaining === 0) {
deferred.resolve({}); resolve(results);
} }
var resolver = function(prop) { function resolver(key) {
return function(value) { return function(value) {
resolveAll(prop, value); resolveAll(key, value);
};
}; };
}
var resolveAll = function(prop, value) { function resolveAll(key, value) {
results[prop] = value; results[key] = value;
if (--remaining === 0) { if (--remaining === 0) {
deferred.resolve(results); resolve(results);
}
} }
};
var rejectAll = function(error) { function cancelAll(rejectionValue) {
deferred.reject(error); reject(rejectionValue);
}; canceller();
}
for (var prop in promises) { for (var prop in promises) {
if (promises[prop] && typeof promises[prop].then === 'function') { promise = promises[prop];
promises[prop].then(resolver(prop), rejectAll);
if (promise && typeof promise.then === 'function') {
promise.then(resolver(prop), cancelAll);
} else { } else {
resolveAll(prop, promises[prop]); resolveAll(prop, promise);
} }
} }
return deferred.promise; }, canceller
);
} }
...@@ -504,11 +546,6 @@ define("rsvp/promise", ...@@ -504,11 +546,6 @@ define("rsvp/promise",
reject(promise, value); reject(promise, value);
}; };
var notifyPromise = function(value) {
if (resolved) { return; }
notify(promise, value);
};
this.on('promise:failed', function(event) { this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail }); this.trigger('error', { detail: event.detail });
}, this); }, this);
...@@ -519,6 +556,7 @@ define("rsvp/promise", ...@@ -519,6 +556,7 @@ define("rsvp/promise",
// For now, simply reject the promise and does not propagate the cancel // For now, simply reject the promise and does not propagate the cancel
// to parent or children // to parent or children
if (resolved) { return; } if (resolved) { return; }
promise.isCancelled = true;
if (canceller !== undefined) { if (canceller !== undefined) {
try { try {
canceller(); canceller();
...@@ -532,7 +570,7 @@ define("rsvp/promise", ...@@ -532,7 +570,7 @@ define("rsvp/promise",
}; };
try { try {
resolver(resolvePromise, rejectPromise, notifyPromise); resolver(resolvePromise, rejectPromise);
} catch(e) { } catch(e) {
rejectPromise(e); rejectPromise(e);
} }
...@@ -550,6 +588,7 @@ define("rsvp/promise", ...@@ -550,6 +588,7 @@ define("rsvp/promise",
if (promise.isFulfilled) { return; } if (promise.isFulfilled) { return; }
if (promise.isRejected) { return; } if (promise.isRejected) { return; }
if (promise.isCancelled) { return; }
if (hasCallback) { if (hasCallback) {
try { try {
...@@ -577,31 +616,16 @@ define("rsvp/promise", ...@@ -577,31 +616,16 @@ define("rsvp/promise",
} }
}; };
var invokeNotifyCallback = function(promise, callback, event) {
var value;
if (typeof callback === 'function') {
try {
value = callback(event.detail);
} catch (e) {
// stop propagating
return;
}
notify(promise, value);
} else {
notify(promise, event.detail);
}
};
Promise.prototype = { Promise.prototype = {
constructor: Promise, constructor: Promise,
isCancelled: undefined,
isRejected: undefined, isRejected: undefined,
isFulfilled: undefined, isFulfilled: undefined,
rejectedReason: undefined, rejectedReason: undefined,
fulfillmentValue: undefined, fulfillmentValue: undefined,
then: function(done, fail, progress) { then: function(done, fail) {
this.off('error', onerror); this.off('error', onerror);
var thenPromise = new this.constructor(function() {}, var thenPromise = new this.constructor(function() {},
...@@ -629,10 +653,6 @@ define("rsvp/promise", ...@@ -629,10 +653,6 @@ define("rsvp/promise",
invokeCallback('reject', thenPromise, fail, event); invokeCallback('reject', thenPromise, fail, event);
}); });
this.on('promise:notified', function (event) {
invokeNotifyCallback(thenPromise, progress, event);
});
return thenPromise; return thenPromise;
}, },
...@@ -720,21 +740,15 @@ define("rsvp/promise", ...@@ -720,21 +740,15 @@ define("rsvp/promise",
}); });
} }
function notify(promise, value) {
config.async(function() {
promise.trigger('promise:notified', { detail: value });
});
}
__exports__.Promise = Promise; __exports__.Promise = Promise;
}); });
define("rsvp/queue", define("rsvp/queue",
["rsvp/promise","rsvp/timeout","exports"], ["rsvp/promise","rsvp/resolve","exports"],
function(__dependency1__, __dependency2__, __exports__) { function(__dependency1__, __dependency2__, __exports__) {
"use strict"; "use strict";
var Promise = __dependency1__.Promise; var Promise = __dependency1__.Promise;
var delay = __dependency2__.delay; var resolve = __dependency2__.resolve;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
function ResolvedQueueError(message) { function ResolvedQueueError(message) {
...@@ -747,7 +761,7 @@ define("rsvp/queue", ...@@ -747,7 +761,7 @@ define("rsvp/queue",
ResolvedQueueError.prototype = new Error(); ResolvedQueueError.prototype = new Error();
ResolvedQueueError.prototype.constructor = ResolvedQueueError; ResolvedQueueError.prototype.constructor = ResolvedQueueError;
var Queue = function() { var Queue = function(thenable) {
var queue = this, var queue = this,
promise_list = [], promise_list = [],
promise, promise,
...@@ -760,9 +774,29 @@ define("rsvp/queue", ...@@ -760,9 +774,29 @@ define("rsvp/queue",
} }
function canceller() { function canceller() {
for (var i = 0; i < 2; i++) { for (var i = promise_list.length; i > 0; i--) {
promise_list[i].cancel(); promise_list[i - 1].cancel();
}
}
function checkPromise(next_promise) {
promise_list.push(next_promise);
// Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
} }
}));
} }
promise = new Promise(function(done, fail) { promise = new Promise(function(done, fail) {
...@@ -782,13 +816,7 @@ define("rsvp/queue", ...@@ -782,13 +816,7 @@ define("rsvp/queue",
}; };
}, canceller); }, canceller);
promise_list.push(delay()); checkPromise(resolve(thenable));
promise_list.push(promise_list[0].then(function () {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill();
}
}));
queue.cancel = function () { queue.cancel = function () {
if (resolved) {return;} if (resolved) {return;}
...@@ -811,25 +839,9 @@ define("rsvp/queue", ...@@ -811,25 +839,9 @@ define("rsvp/queue",
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail);
promise_list.push(next_promise);
// Handle pop // Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) { checkPromise(last_promise.then(done, fail));
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
return this; return this;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment