Commit 7c8fc367 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_xhtml_style/erp5_web_renderjs_ui] Activate RSVP native promise async

parent 44f24691
(function(globals) { (function(globals) {
var define, requireModule; var define, requireModule;
(function() { (function() {
var registry = {}, seen = {}; var registry = {}, seen = {};
define = function(name, deps, callback) { define = function(name, deps, callback) {
registry[name] = { deps: deps, callback: callback }; registry[name] = { deps: deps, callback: callback };
}; };
requireModule = function(name) { requireModule = function(name) {
if (seen[name]) { return seen[name]; } if (seen[name]) { return seen[name]; }
seen[name] = {}; seen[name] = {};
var mod = registry[name]; var mod = registry[name];
if (!mod) { if (!mod) {
throw new Error("Module '" + name + "' not found."); throw new Error("Module '" + name + "' not found.");
} }
var deps = mod.deps, var deps = mod.deps,
callback = mod.callback, callback = mod.callback,
reified = [], reified = [],
exports; exports;
for (var i=0, l=deps.length; i<l; i++) { for (var i=0, l=deps.length; i<l; i++) {
if (deps[i] === 'exports') { if (deps[i] === 'exports') {
reified.push(exports = {}); reified.push(exports = {});
} else { } else {
reified.push(requireModule(deps[i])); reified.push(requireModule(deps[i]));
} }
} }
var value = callback.apply(this, reified); var value = callback.apply(this, reified);
return seen[name] = exports || value; return seen[name] = exports || value;
}; };
})(); })();
define("rsvp/all", define("rsvp/all",
["rsvp/promise","exports"], ["rsvp/promise","exports"],
function(__dependency1__, __exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var Promise = __dependency1__.Promise; var Promise = __dependency1__.Promise;
/* global toString */ /* global toString */
function promiseAtLeast(expected_count, promises) { function promiseAtLeast(expected_count, promises) {
if (Object.prototype.toString.call(promises) !== "[object Array]") { if (Object.prototype.toString.call(promises) !== "[object Array]") {
throw new TypeError('You must pass an array to all.'); throw new TypeError('You must pass an array to all.');
} }
function canceller() { function canceller() {
var promise; var promise;
for (var i = 0; i < promises.length; i++) { for (var i = 0; i < promises.length; i++) {
promise = promises[i]; promise = promises[i];
if (promise && typeof promise.then === 'function' && if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') { typeof promise.cancel === 'function') {
promise.cancel(); promise.cancel();
} }
} }
} }
return new Promise(function(resolve, reject, notify) { return new Promise(function(resolve, reject, notify) {
var results = [], remaining = promises.length, var results = [], remaining = promises.length,
promise, remaining_count = promises.length - expected_count; promise, remaining_count = promises.length - expected_count;
if (remaining === 0) { if (remaining === 0) {
if (expected_count === 1) { if (expected_count === 1) {
resolve(); resolve();
} else { } else {
resolve([]); resolve([]);
} }
} }
function resolver(index) { function resolver(index) {
return function(value) { return function(value) {
resolveAll(index, value); resolveAll(index, value);
}; };
} }
function resolveAll(index, value) { function resolveAll(index, value) {
results[index] = value; results[index] = value;
if (--remaining === remaining_count) { if (--remaining === remaining_count) {
if (remaining_count === 0) { if (remaining_count === 0) {
resolve(results); resolve(results);
} else { } else {
resolve(value); resolve(value);
canceller(); canceller();
} }
} }
} }
function notifier(index) { function notifier(index) {
return function(value) { return function(value) {
notify({"index": index, "value": value}); notify({"index": index, "value": value});
}; };
} }
function cancelAll(rejectionValue) { function cancelAll(rejectionValue) {
reject(rejectionValue); reject(rejectionValue);
canceller(); canceller();
} }
for (var i = 0; i < promises.length; i++) { for (var i = 0; i < promises.length; i++) {
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, notifier(i));
} else { } else {
resolveAll(i, promise); resolveAll(i, promise);
} }
} }
}, canceller }, canceller
); );
} }
function all(promises) { function all(promises) {
return promiseAtLeast(promises.length, promises); return promiseAtLeast(promises.length, promises);
} }
function any(promises) { function any(promises) {
return promiseAtLeast(1, promises); return promiseAtLeast(1, promises);
} }
__exports__.all = all; __exports__.all = all;
__exports__.any = any; __exports__.any = any;
}); });
define("rsvp/async", define("rsvp/async",
["exports"], ["exports"],
function(__exports__) { function(__exports__) {
"use strict"; "use strict";
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var async;
var local = (typeof global !== 'undefined') ? global : this; var local = (typeof global !== 'undefined') ? global : this;
// old node function checkNativePromise() {
function useNextTick() { if (typeof Promise === "function" &&
return function(callback, arg) { typeof Promise.resolve === "function") {
process.nextTick(function() { try {
callback(arg); /* global Promise */
}); var promise = new Promise(function(){});
}; if ({}.toString.call(promise) === "[object Promise]") {
} return true;
}
// node >= 0.10.x } catch (e) {}
function useSetImmediate() { }
return function(callback, arg) { return false;
/* global setImmediate */ }
setImmediate(function(){
callback(arg); function useNativePromise() {
}); var nativePromise = Promise.resolve();
}; return function(callback, arg) {
} nativePromise.then(function () {
callback(arg);
function useMutationObserver() { });
var queue = []; };
}
var observer = new BrowserMutationObserver(function() {
var toProcess = queue.slice(); // old node
queue = []; function useNextTick() {
return function(callback, arg) {
toProcess.forEach(function(tuple) { process.nextTick(function() {
var callback = tuple[0], arg= tuple[1]; callback(arg);
callback(arg); });
}); };
}); }
var element = document.createElement('div'); // node >= 0.10.x
observer.observe(element, { attributes: true }); function useSetImmediate() {
return function(callback, arg) {
// Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661 /* global setImmediate */
window.addEventListener('unload', function(){ setImmediate(function(){
observer.disconnect(); callback(arg);
observer = null; });
}, false); };
}
return function(callback, arg) {
queue.push([callback, arg]); function useMutationObserver() {
element.setAttribute('drainQueue', 'drainQueue'); var queue = [];
};
} var observer = new BrowserMutationObserver(function() {
var toProcess = queue.slice();
function useSetTimeout() { queue = [];
return function(callback, arg) {
local.setTimeout(function() { toProcess.forEach(function(tuple) {
callback(arg); var callback = tuple[0], arg= tuple[1];
}, 1); callback(arg);
}; });
} });
if (typeof setImmediate === 'function') { var element = document.createElement('div');
async = useSetImmediate(); observer.observe(element, { attributes: true });
} else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
async = useNextTick(); // Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661
} else if (BrowserMutationObserver) { window.addEventListener('unload', function(){
async = useMutationObserver(); observer.disconnect();
} else { observer = null;
async = useSetTimeout(); }, false);
}
return function(callback, arg) {
queue.push([callback, arg]);
__exports__.async = async; element.setAttribute('drainQueue', 'drainQueue');
}); };
define("rsvp/cancellation_error", }
["exports"],
function(__exports__) { function useSetTimeout() {
"use strict"; return function(callback, arg) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error local.setTimeout(function() {
function CancellationError(message) { callback(arg);
this.name = "cancel"; }, 1);
if ((message !== undefined) && (typeof message !== "string")) { };
throw new TypeError('You must pass a string.'); }
}
this.message = message || "Default Message"; if (typeof setImmediate === 'function') {
} async = useSetImmediate();
CancellationError.prototype = new Error(); } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
CancellationError.prototype.constructor = CancellationError; async = useNextTick();
} else if (BrowserMutationObserver) {
async = useMutationObserver();
__exports__.CancellationError = CancellationError; } else if (checkNativePromise()) {
}); async = useNativePromise();
define("rsvp/config", } else {
["rsvp/async","exports"], async = useSetTimeout();
function(__dependency1__, __exports__) { }
"use strict";
var async = __dependency1__.async;
__exports__.async = async;
var config = {}; });
config.async = async; define("rsvp/cancellation_error",
["exports"],
function(__exports__) {
__exports__.config = config; "use strict";
}); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
define("rsvp/defer", function CancellationError(message) {
["rsvp/promise","exports"], this.name = "cancel";
function(__dependency1__, __exports__) { if ((message !== undefined) && (typeof message !== "string")) {
"use strict"; throw new TypeError('You must pass a string.');
var Promise = __dependency1__.Promise; }
this.message = message || "Default Message";
function defer() { }
var deferred = { CancellationError.prototype = new Error();
// pre-allocate shape CancellationError.prototype.constructor = CancellationError;
resolve: undefined,
reject: undefined,
promise: undefined __exports__.CancellationError = CancellationError;
}; });
define("rsvp/config",
deferred.promise = new Promise(function(resolve, reject) { ["rsvp/async","exports"],
deferred.resolve = resolve; function(__dependency1__, __exports__) {
deferred.reject = reject; "use strict";
}); var async = __dependency1__.async;
return deferred; var config = {};
} config.async = async;
__exports__.defer = defer; __exports__.config = config;
}); });
define("rsvp/events", define("rsvp/defer",
["exports"], ["rsvp/promise","exports"],
function(__exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var Event = function(type, options) { var Promise = __dependency1__.Promise;
this.type = type;
function defer() {
for (var option in options) { var deferred = {
if (!options.hasOwnProperty(option)) { continue; } // pre-allocate shape
resolve: undefined,
this[option] = options[option]; reject: undefined,
} promise: undefined
}; };
var indexOf = function(callbacks, callback) { deferred.promise = new Promise(function(resolve, reject) {
for (var i=0, l=callbacks.length; i<l; i++) { deferred.resolve = resolve;
if (callbacks[i][0] === callback) { return i; } deferred.reject = reject;
} });
return -1; return deferred;
}; }
var callbacksFor = function(object) {
var callbacks = object._promiseCallbacks; __exports__.defer = defer;
});
if (!callbacks) { define("rsvp/events",
callbacks = object._promiseCallbacks = {}; ["exports"],
} function(__exports__) {
"use strict";
return callbacks; var Event = function(type, options) {
}; this.type = type;
var EventTarget = { for (var option in options) {
mixin: function(object) { if (!options.hasOwnProperty(option)) { continue; }
object.on = this.on;
object.off = this.off; this[option] = options[option];
object.trigger = this.trigger; }
return object; };
},
var indexOf = function(callbacks, callback) {
on: function(eventNames, callback, binding) { for (var i=0, l=callbacks.length; i<l; i++) {
var allCallbacks = callbacksFor(this), callbacks, eventName; if (callbacks[i][0] === callback) { return i; }
eventNames = eventNames.split(/\s+/); }
binding = binding || this;
return -1;
while (eventName = eventNames.shift()) { };
callbacks = allCallbacks[eventName];
var callbacksFor = function(object) {
if (!callbacks) { var callbacks = object._promiseCallbacks;
callbacks = allCallbacks[eventName] = [];
} if (!callbacks) {
callbacks = object._promiseCallbacks = {};
if (indexOf(callbacks, callback) === -1) { }
callbacks.push([callback, binding]);
} return callbacks;
} };
},
var EventTarget = {
off: function(eventNames, callback) { mixin: function(object) {
var allCallbacks = callbacksFor(this), callbacks, eventName, index; object.on = this.on;
eventNames = eventNames.split(/\s+/); object.off = this.off;
object.trigger = this.trigger;
while (eventName = eventNames.shift()) { return object;
if (!callback) { },
allCallbacks[eventName] = [];
continue; on: function(eventNames, callback, binding) {
} var allCallbacks = callbacksFor(this), callbacks, eventName;
eventNames = eventNames.split(/\s+/);
callbacks = allCallbacks[eventName]; binding = binding || this;
index = indexOf(callbacks, callback); while (eventName = eventNames.shift()) {
callbacks = allCallbacks[eventName];
if (index !== -1) { callbacks.splice(index, 1); }
} if (!callbacks) {
}, callbacks = allCallbacks[eventName] = [];
}
trigger: function(eventName, options) {
var allCallbacks = callbacksFor(this), if (indexOf(callbacks, callback) === -1) {
callbacks, callbackTuple, callback, binding, event; callbacks.push([callback, binding]);
}
if (callbacks = allCallbacks[eventName]) { }
// Don't cache the callbacks.length since it may grow },
for (var i=0; i<callbacks.length; i++) {
callbackTuple = callbacks[i]; off: function(eventNames, callback) {
callback = callbackTuple[0]; var allCallbacks = callbacksFor(this), callbacks, eventName, index;
binding = callbackTuple[1]; eventNames = eventNames.split(/\s+/);
if (typeof options !== 'object') { while (eventName = eventNames.shift()) {
options = { detail: options }; if (!callback) {
} allCallbacks[eventName] = [];
continue;
event = new Event(eventName, options); }
callback.call(binding, event);
} callbacks = allCallbacks[eventName];
}
} index = indexOf(callbacks, callback);
};
if (index !== -1) { callbacks.splice(index, 1); }
}
__exports__.EventTarget = EventTarget; },
});
define("rsvp/hash", trigger: function(eventName, options) {
["rsvp/defer","exports"], var allCallbacks = callbacksFor(this),
function(__dependency1__, __exports__) { callbacks, callbackTuple, callback, binding, event;
"use strict";
var defer = __dependency1__.defer; if (callbacks = allCallbacks[eventName]) {
// Don't cache the callbacks.length since it may grow
function size(object) { for (var i=0; i<callbacks.length; i++) {
var s = 0; callbackTuple = callbacks[i];
callback = callbackTuple[0];
for (var prop in object) { binding = callbackTuple[1];
s++;
} if (typeof options !== 'object') {
options = { detail: options };
return s; }
}
event = new Event(eventName, options);
function hash(promises) { callback.call(binding, event);
var results = {}, deferred = defer(), remaining = size(promises); }
}
if (remaining === 0) { }
deferred.resolve({}); };
}
var resolver = function(prop) { __exports__.EventTarget = EventTarget;
return function(value) { });
resolveAll(prop, value); define("rsvp/hash",
}; ["rsvp/defer","exports"],
}; function(__dependency1__, __exports__) {
"use strict";
var resolveAll = function(prop, value) { var defer = __dependency1__.defer;
results[prop] = value;
if (--remaining === 0) { function size(object) {
deferred.resolve(results); var s = 0;
}
}; for (var prop in object) {
s++;
var rejectAll = function(error) { }
deferred.reject(error);
}; return s;
}
for (var prop in promises) {
if (promises[prop] && typeof promises[prop].then === 'function') { function hash(promises) {
promises[prop].then(resolver(prop), rejectAll); var results = {}, deferred = defer(), remaining = size(promises);
} else {
resolveAll(prop, promises[prop]); if (remaining === 0) {
} deferred.resolve({});
} }
return deferred.promise; var resolver = function(prop) {
} return function(value) {
resolveAll(prop, value);
};
__exports__.hash = hash; };
});
define("rsvp/node", var resolveAll = function(prop, value) {
["rsvp/promise","rsvp/all","exports"], results[prop] = value;
function(__dependency1__, __dependency2__, __exports__) { if (--remaining === 0) {
"use strict"; deferred.resolve(results);
var Promise = __dependency1__.Promise; }
var all = __dependency2__.all; };
function makeNodeCallbackFor(resolve, reject) { var rejectAll = function(error) {
return function (error, value) { deferred.reject(error);
if (error) { };
reject(error);
} else if (arguments.length > 2) { for (var prop in promises) {
resolve(Array.prototype.slice.call(arguments, 1)); if (promises[prop] && typeof promises[prop].then === 'function') {
} else { promises[prop].then(resolver(prop), rejectAll);
resolve(value); } else {
} resolveAll(prop, promises[prop]);
}; }
} }
function denodeify(nodeFunc) { return deferred.promise;
return function() { }
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var thisArg = this;
__exports__.hash = hash;
var promise = new Promise(function(nodeResolve, nodeReject) { });
resolve = nodeResolve; define("rsvp/node",
reject = nodeReject; ["rsvp/promise","rsvp/all","exports"],
}); function(__dependency1__, __dependency2__, __exports__) {
"use strict";
all(nodeArgs).then(function(nodeArgs) { var Promise = __dependency1__.Promise;
nodeArgs.push(makeNodeCallbackFor(resolve, reject)); var all = __dependency2__.all;
try { function makeNodeCallbackFor(resolve, reject) {
nodeFunc.apply(thisArg, nodeArgs); return function (error, value) {
} catch(e) { if (error) {
reject(e); reject(error);
} } else if (arguments.length > 2) {
}); resolve(Array.prototype.slice.call(arguments, 1));
} else {
return promise; resolve(value);
}; }
} };
}
__exports__.denodeify = denodeify; function denodeify(nodeFunc) {
}); return function() {
define("rsvp/promise", var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
["rsvp/config","rsvp/events","rsvp/cancellation_error","exports"], var thisArg = this;
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
"use strict"; var promise = new Promise(function(nodeResolve, nodeReject) {
var config = __dependency1__.config; resolve = nodeResolve;
var EventTarget = __dependency2__.EventTarget; reject = nodeReject;
var CancellationError = __dependency3__.CancellationError; });
function objectOrFunction(x) { all(nodeArgs).then(function(nodeArgs) {
return isFunction(x) || (typeof x === "object" && x !== null); nodeArgs.push(makeNodeCallbackFor(resolve, reject));
}
try {
function isFunction(x){ nodeFunc.apply(thisArg, nodeArgs);
return typeof x === "function"; } catch(e) {
} reject(e);
}
var Promise = function(resolver, canceller) { });
var promise = this,
resolved = false; return promise;
};
if (typeof resolver !== 'function') { }
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
__exports__.denodeify = denodeify;
if ((canceller !== undefined) && (typeof canceller !== 'function')) { });
throw new TypeError('You can only pass a canceller function' + define("rsvp/promise",
' as the second argument to the promise constructor'); ["rsvp/config","rsvp/events","rsvp/cancellation_error","exports"],
} function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
"use strict";
if (!(promise instanceof Promise)) { var config = __dependency1__.config;
return new Promise(resolver, canceller); var EventTarget = __dependency2__.EventTarget;
} var CancellationError = __dependency3__.CancellationError;
var resolvePromise = function(value) { function objectOrFunction(x) {
if (resolved) { return; } return isFunction(x) || (typeof x === "object" && x !== null);
resolved = true; }
resolve(promise, value);
}; function isFunction(x){
return typeof x === "function";
var rejectPromise = function(value) { }
if (resolved) { return; }
resolved = true; var Promise = function(resolver, canceller) {
reject(promise, value); var promise = this,
}; resolved = false;
var notifyPromise = function(value) { if (typeof resolver !== 'function') {
if (resolved) { return; } throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
notify(promise, value); }
};
if ((canceller !== undefined) && (typeof canceller !== 'function')) {
this.on('promise:failed', function(event) { throw new TypeError('You can only pass a canceller function' +
this.trigger('error', { detail: event.detail }); ' as the second argument to the promise constructor');
}, this); }
this.on('error', onerror); if (!(promise instanceof Promise)) {
return new Promise(resolver, canceller);
this.cancel = function () { }
// For now, simply reject the promise and does not propagate the cancel
// to parent or children var resolvePromise = function(value) {
if (resolved) { return; } if (resolved) { return; }
if (canceller !== undefined) { resolved = true;
try { resolve(promise, value);
canceller(); };
} catch (e) {
rejectPromise(e); var rejectPromise = function(value) {
return; if (resolved) { return; }
} resolved = true;
} reject(promise, value);
// Trigger cancel? };
rejectPromise(new CancellationError());
}; var notifyPromise = function(value) {
if (resolved) { return; }
try { notify(promise, value);
resolver(resolvePromise, rejectPromise, notifyPromise); };
} catch(e) {
rejectPromise(e); this.on('promise:failed', function(event) {
} this.trigger('error', { detail: event.detail });
}; }, this);
function onerror(event) { this.on('error', onerror);
if (config.onerror) {
config.onerror(event.detail); this.cancel = function () {
} // For now, simply reject the promise and does not propagate the cancel
} // to parent or children
if (resolved) { return; }
var invokeCallback = function(type, promise, callback, event) { if (canceller !== undefined) {
var hasCallback = isFunction(callback), try {
value, error, succeeded, failed; canceller();
} catch (e) {
if (promise.isFulfilled) { return; } rejectPromise(e);
if (promise.isRejected) { return; } return;
}
if (hasCallback) { }
try { // Trigger cancel?
value = callback(event.detail); rejectPromise(new CancellationError());
succeeded = true; };
} catch(e) {
failed = true; try {
error = e; resolver(resolvePromise, rejectPromise, notifyPromise);
} } catch(e) {
} else { rejectPromise(e);
value = event.detail; }
succeeded = true; };
}
function onerror(event) {
if (handleThenable(promise, value)) { if (config.onerror) {
return; config.onerror(event.detail);
} else if (hasCallback && succeeded) { }
resolve(promise, value); }
} else if (failed) {
reject(promise, error); var invokeCallback = function(type, promise, callback, event) {
} else if (type === 'resolve') { var hasCallback = isFunction(callback),
resolve(promise, value); value, error, succeeded, failed;
} else if (type === 'reject') {
reject(promise, value); if (promise.isFulfilled) { return; }
} if (promise.isRejected) { return; }
};
if (hasCallback) {
try {
var invokeNotifyCallback = function(promise, callback, event) { value = callback(event.detail);
var value; succeeded = true;
if (typeof callback === 'function') { } catch(e) {
try { failed = true;
value = callback(event.detail); error = e;
} catch (e) { }
// stop propagating } else {
return; value = event.detail;
} succeeded = true;
notify(promise, value); }
} else {
notify(promise, event.detail); if (handleThenable(promise, value)) {
} return;
}; } else if (hasCallback && succeeded) {
resolve(promise, value);
Promise.prototype = { } else if (failed) {
constructor: Promise, reject(promise, error);
} else if (type === 'resolve') {
isRejected: undefined, resolve(promise, value);
isFulfilled: undefined, } else if (type === 'reject') {
rejectedReason: undefined, reject(promise, value);
fulfillmentValue: undefined, }
};
then: function(done, fail, progress) {
this.off('error', onerror);
var invokeNotifyCallback = function(promise, callback, event) {
var thenPromise = new this.constructor(function() {}, var value;
function () { if (typeof callback === 'function') {
thenPromise.trigger('promise:cancelled', {}); try {
}); value = callback(event.detail);
} catch (e) {
if (this.isFulfilled) { // stop propagating
config.async(function(promise) { return;
invokeCallback('resolve', thenPromise, done, { detail: promise.fulfillmentValue }); }
}, this); notify(promise, value);
} } else {
notify(promise, event.detail);
if (this.isRejected) { }
config.async(function(promise) { };
invokeCallback('reject', thenPromise, fail, { detail: promise.rejectedReason });
}, this); Promise.prototype = {
} constructor: Promise,
this.on('promise:resolved', function(event) { isRejected: undefined,
invokeCallback('resolve', thenPromise, done, event); isFulfilled: undefined,
}); rejectedReason: undefined,
fulfillmentValue: undefined,
this.on('promise:failed', function(event) {
invokeCallback('reject', thenPromise, fail, event); then: function(done, fail, progress) {
}); this.off('error', onerror);
this.on('promise:notified', function (event) { var thenPromise = new this.constructor(function() {},
invokeNotifyCallback(thenPromise, progress, event); function () {
}); thenPromise.trigger('promise:cancelled', {});
});
return thenPromise;
}, if (this.isFulfilled) {
config.async(function(promise) {
fail: function(fail) { invokeCallback('resolve', thenPromise, done, { detail: promise.fulfillmentValue });
return this.then(null, fail); }, this);
}, }
always: function(fail) { if (this.isRejected) {
return this.then(fail, fail); config.async(function(promise) {
} invokeCallback('reject', thenPromise, fail, { detail: promise.rejectedReason });
}; }, this);
}
EventTarget.mixin(Promise.prototype);
this.on('promise:resolved', function(event) {
function resolve(promise, value) { invokeCallback('resolve', thenPromise, done, event);
if (promise === value) { });
fulfill(promise, value);
} else if (!handleThenable(promise, value)) { this.on('promise:failed', function(event) {
fulfill(promise, value); invokeCallback('reject', thenPromise, fail, event);
} });
}
this.on('promise:notified', function (event) {
function handleThenable(promise, value) { invokeNotifyCallback(thenPromise, progress, event);
var then = null, });
resolved;
return thenPromise;
try { },
if (promise === value) {
throw new TypeError("A promises callback cannot return that same promise."); fail: function(fail) {
} return this.then(null, fail);
},
if (objectOrFunction(value)) {
then = value.then; always: function(fail) {
return this.then(fail, fail);
if (isFunction(then)) { }
if (isFunction(value.on)) { };
value.on('promise:notified', function (event) {
notify(promise, event.detail); EventTarget.mixin(Promise.prototype);
});
} function resolve(promise, value) {
promise.on('promise:cancelled', function(event) { if (promise === value) {
if (isFunction(value.cancel)) { fulfill(promise, value);
value.cancel(); } else if (!handleThenable(promise, value)) {
} fulfill(promise, value);
}); }
then.call(value, function(val) { }
if (resolved) { return true; }
resolved = true; function handleThenable(promise, value) {
var then = null,
if (value !== val) { resolved;
resolve(promise, val);
} else { try {
fulfill(promise, val); if (promise === value) {
} throw new TypeError("A promises callback cannot return that same promise.");
}, function(val) { }
if (resolved) { return true; }
resolved = true; if (objectOrFunction(value)) {
then = value.then;
reject(promise, val);
}); if (isFunction(then)) {
if (isFunction(value.on)) {
return true; value.on('promise:notified', function (event) {
} notify(promise, event.detail);
} });
} catch (error) { }
reject(promise, error); promise.on('promise:cancelled', function(event) {
return true; if (isFunction(value.cancel)) {
} value.cancel();
}
return false; });
} then.call(value, function(val) {
if (resolved) { return true; }
function fulfill(promise, value) { resolved = true;
config.async(function() {
if (promise.isFulfilled) { return; } if (value !== val) {
if (promise.isRejected) { return; } resolve(promise, val);
promise.trigger('promise:resolved', { detail: value }); } else {
promise.isFulfilled = true; fulfill(promise, val);
promise.fulfillmentValue = value; }
}); }, function(val) {
} if (resolved) { return true; }
resolved = true;
function reject(promise, value) {
config.async(function() { reject(promise, val);
if (promise.isFulfilled) { return; } });
if (promise.isRejected) { return; }
promise.trigger('promise:failed', { detail: value }); return true;
promise.isRejected = true; }
promise.rejectedReason = value; }
}); } catch (error) {
} reject(promise, error);
return true;
function notify(promise, value) { }
config.async(function() {
promise.trigger('promise:notified', { detail: value }); return false;
}); }
}
function fulfill(promise, value) {
config.async(function() {
__exports__.Promise = Promise; if (promise.isFulfilled) { return; }
}); if (promise.isRejected) { return; }
define("rsvp/queue", promise.trigger('promise:resolved', { detail: value });
["rsvp/promise","rsvp/resolve","exports"], promise.isFulfilled = true;
function(__dependency1__, __dependency2__, __exports__) { promise.fulfillmentValue = value;
"use strict"; });
var Promise = __dependency1__.Promise; }
var resolve = __dependency2__.resolve;
function reject(promise, value) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error config.async(function() {
function ResolvedQueueError(message) { if (promise.isFulfilled) { return; }
this.name = "resolved"; if (promise.isRejected) { return; }
if ((message !== undefined) && (typeof message !== "string")) { promise.trigger('promise:failed', { detail: value });
throw new TypeError('You must pass a string.'); promise.isRejected = true;
} promise.rejectedReason = value;
this.message = message || "Default Message"; });
} }
ResolvedQueueError.prototype = new Error();
ResolvedQueueError.prototype.constructor = ResolvedQueueError; function notify(promise, value) {
config.async(function() {
var Queue = function() { promise.trigger('promise:notified', { detail: value });
var queue = this, });
promise_list = [], }
promise,
fulfill,
reject, __exports__.Promise = Promise;
notify, });
resolved; define("rsvp/queue",
["rsvp/promise","rsvp/resolve","exports"],
if (!(this instanceof Queue)) { function(__dependency1__, __dependency2__, __exports__) {
return new Queue(); "use strict";
} var Promise = __dependency1__.Promise;
var resolve = __dependency2__.resolve;
function canceller() {
for (var i = 0; i < 2; i++) { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
promise_list[i].cancel(); function ResolvedQueueError(message) {
} this.name = "resolved";
} if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
promise = new Promise(function(done, fail, progress) { }
fulfill = function (fulfillmentValue) { this.message = message || "Default Message";
if (resolved) {return;} }
queue.isFulfilled = true; ResolvedQueueError.prototype = new Error();
queue.fulfillmentValue = fulfillmentValue; ResolvedQueueError.prototype.constructor = ResolvedQueueError;
resolved = true;
return done(fulfillmentValue); var Queue = function() {
}; var queue = this,
reject = function (rejectedReason) { promise_list = [],
if (resolved) {return;} promise,
queue.isRejected = true; fulfill,
queue.rejectedReason = rejectedReason ; reject,
resolved = true; notify,
return fail(rejectedReason); resolved;
};
notify = progress; if (!(this instanceof Queue)) {
}, canceller); return new Queue();
}
promise_list.push(resolve());
promise_list.push(promise_list[0].then(function () { function canceller() {
promise_list.splice(0, 2); for (var i = 0; i < 2; i++) {
if (promise_list.length === 0) { promise_list[i].cancel();
fulfill(); }
} }
}));
promise = new Promise(function(done, fail, progress) {
queue.cancel = function () { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
resolved = true; queue.isFulfilled = true;
promise.cancel(); queue.fulfillmentValue = fulfillmentValue;
promise.fail(function (rejectedReason) { resolved = true;
queue.isRejected = true; return done(fulfillmentValue);
queue.rejectedReason = rejectedReason; };
}); reject = function (rejectedReason) {
}; if (resolved) {return;}
queue.then = function () { queue.isRejected = true;
return promise.then.apply(promise, arguments); queue.rejectedReason = rejectedReason ;
}; resolved = true;
return fail(rejectedReason);
queue.push = function(done, fail, progress) { };
var last_promise = promise_list[promise_list.length - 1], notify = progress;
next_promise; }, canceller);
if (resolved) { promise_list.push(resolve());
throw new ResolvedQueueError(); promise_list.push(promise_list[0].then(function () {
} promise_list.splice(0, 2);
if (promise_list.length === 0) {
next_promise = last_promise.then(done, fail, progress); fulfill();
promise_list.push(next_promise); }
}));
// Handle pop
last_promise = next_promise.then(function (fulfillmentValue) { queue.cancel = function () {
promise_list.splice(0, 2); if (resolved) {return;}
if (promise_list.length === 0) { resolved = true;
fulfill(fulfillmentValue); promise.cancel();
} else { promise.fail(function (rejectedReason) {
return fulfillmentValue; queue.isRejected = true;
} queue.rejectedReason = rejectedReason;
}, function (rejectedReason) { });
promise_list.splice(0, 2); };
if (promise_list.length === 0) { queue.then = function () {
reject(rejectedReason); return promise.then.apply(promise, arguments);
} else { };
throw rejectedReason;
} queue.push = function(done, fail, progress) {
}, function (notificationValue) { var last_promise = promise_list[promise_list.length - 1],
if (promise_list[promise_list.length - 1] === last_promise) { next_promise;
notify(notificationValue);
} if (resolved) {
return notificationValue; throw new ResolvedQueueError();
}); }
promise_list.push(last_promise);
next_promise = last_promise.then(done, fail, progress);
return this; promise_list.push(next_promise);
};
}; // Handle pop
last_promise = next_promise.then(function (fulfillmentValue) {
Queue.prototype = Object.create(Promise.prototype); promise_list.splice(0, 2);
Queue.prototype.constructor = Queue; if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
__exports__.Queue = Queue; return fulfillmentValue;
__exports__.ResolvedQueueError = ResolvedQueueError; }
}); }, function (rejectedReason) {
define("rsvp/reject", promise_list.splice(0, 2);
["rsvp/promise","exports"], if (promise_list.length === 0) {
function(__dependency1__, __exports__) { reject(rejectedReason);
"use strict"; } else {
var Promise = __dependency1__.Promise; throw rejectedReason;
}
function reject(reason) { }, function (notificationValue) {
return new Promise(function (resolve, reject) { if (promise_list[promise_list.length - 1] === last_promise) {
reject(reason); notify(notificationValue);
}); }
} return notificationValue;
});
promise_list.push(last_promise);
__exports__.reject = reject;
}); return this;
define("rsvp/resolve", };
["rsvp/promise","exports"], };
function(__dependency1__, __exports__) {
"use strict"; Queue.prototype = Object.create(Promise.prototype);
var Promise = __dependency1__.Promise; Queue.prototype.constructor = Queue;
function resolve(thenable) {
return new Promise(function(resolve, reject) { __exports__.Queue = Queue;
if (typeof thenable === "object" && thenable !== null) { __exports__.ResolvedQueueError = ResolvedQueueError;
var then = thenable.then; });
if ((then !== undefined) && (typeof then === "function")) { define("rsvp/reject",
return then.apply(thenable, [resolve, reject]); ["rsvp/promise","exports"],
} function(__dependency1__, __exports__) {
} "use strict";
return resolve(thenable); var Promise = __dependency1__.Promise;
}, function () {
if ((thenable !== undefined) && (thenable.cancel !== undefined)) { function reject(reason) {
thenable.cancel(); return new Promise(function (resolve, reject) {
} reject(reason);
}); });
} }
__exports__.resolve = resolve; __exports__.reject = reject;
}); });
define("rsvp/rethrow", define("rsvp/resolve",
["exports"], ["rsvp/promise","exports"],
function(__exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var local = (typeof global === "undefined") ? this : global; var Promise = __dependency1__.Promise;
function rethrow(reason) { function resolve(thenable) {
local.setTimeout(function() { return new Promise(function(resolve, reject) {
throw reason; if (typeof thenable === "object" && thenable !== null) {
}); var then = thenable.then;
throw reason; if ((then !== undefined) && (typeof then === "function")) {
} return then.apply(thenable, [resolve, reject]);
}
}
__exports__.rethrow = rethrow; return resolve(thenable);
}); }, function () {
define("rsvp/timeout", if ((thenable !== undefined) && (thenable.cancel !== undefined)) {
["rsvp/promise","exports"], thenable.cancel();
function(__dependency1__, __exports__) { }
"use strict"; });
var Promise = __dependency1__.Promise; }
function promiseSetTimeout(millisecond, should_reject, message) {
var timeout_id; __exports__.resolve = resolve;
});
function resolver(resolve, reject) { define("rsvp/rethrow",
timeout_id = setTimeout(function () { ["exports"],
if (should_reject) { function(__exports__) {
reject(message); "use strict";
} else { var local = (typeof global === "undefined") ? this : global;
resolve(message);
} function rethrow(reason) {
}, millisecond); local.setTimeout(function() {
} throw reason;
function canceller() { });
clearTimeout(timeout_id); throw reason;
} }
return new Promise(resolver, canceller);
}
__exports__.rethrow = rethrow;
function delay(millisecond, message) { });
return promiseSetTimeout(millisecond, false, message); define("rsvp/timeout",
} ["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
function timeout(millisecond) { "use strict";
return promiseSetTimeout(millisecond, true, var Promise = __dependency1__.Promise;
"Timed out after " + millisecond + " ms");
} function promiseSetTimeout(millisecond, should_reject, message) {
var timeout_id;
Promise.prototype.delay = function(millisecond) {
return this.then(function (fulfillmentValue) { function resolver(resolve, reject) {
return delay(millisecond, fulfillmentValue); timeout_id = setTimeout(function () {
}); if (should_reject) {
}; reject(message);
} else {
resolve(message);
__exports__.delay = delay; }
__exports__.timeout = timeout; }, millisecond);
}); }
define("rsvp", function canceller() {
["rsvp/events","rsvp/cancellation_error","rsvp/promise","rsvp/node","rsvp/all","rsvp/queue","rsvp/timeout","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"], clearTimeout(timeout_id);
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __exports__) { }
"use strict"; return new Promise(resolver, canceller);
var EventTarget = __dependency1__.EventTarget; }
var CancellationError = __dependency2__.CancellationError;
var Promise = __dependency3__.Promise; function delay(millisecond, message) {
var denodeify = __dependency4__.denodeify; return promiseSetTimeout(millisecond, false, message);
var all = __dependency5__.all; }
var any = __dependency5__.any;
var Queue = __dependency6__.Queue; function timeout(millisecond) {
var ResolvedQueueError = __dependency6__.ResolvedQueueError; return promiseSetTimeout(millisecond, true,
var delay = __dependency7__.delay; "Timed out after " + millisecond + " ms");
var timeout = __dependency7__.timeout; }
var hash = __dependency8__.hash;
var rethrow = __dependency9__.rethrow; Promise.prototype.delay = function(millisecond) {
var defer = __dependency10__.defer; return this.then(function (fulfillmentValue) {
var config = __dependency11__.config; return delay(millisecond, fulfillmentValue);
var resolve = __dependency12__.resolve; });
var reject = __dependency13__.reject; };
function configure(name, value) {
config[name] = value; __exports__.delay = delay;
} __exports__.timeout = timeout;
});
define("rsvp",
__exports__.CancellationError = CancellationError; ["rsvp/events","rsvp/cancellation_error","rsvp/promise","rsvp/node","rsvp/all","rsvp/queue","rsvp/timeout","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"],
__exports__.Promise = Promise; function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __exports__) {
__exports__.EventTarget = EventTarget; "use strict";
__exports__.all = all; var EventTarget = __dependency1__.EventTarget;
__exports__.any = any; var CancellationError = __dependency2__.CancellationError;
__exports__.Queue = Queue; var Promise = __dependency3__.Promise;
__exports__.ResolvedQueueError = ResolvedQueueError; var denodeify = __dependency4__.denodeify;
__exports__.delay = delay; var all = __dependency5__.all;
__exports__.timeout = timeout; var any = __dependency5__.any;
__exports__.hash = hash; var Queue = __dependency6__.Queue;
__exports__.rethrow = rethrow; var ResolvedQueueError = __dependency6__.ResolvedQueueError;
__exports__.defer = defer; var delay = __dependency7__.delay;
__exports__.denodeify = denodeify; var timeout = __dependency7__.timeout;
__exports__.configure = configure; var hash = __dependency8__.hash;
__exports__.resolve = resolve; var rethrow = __dependency9__.rethrow;
__exports__.reject = reject; var defer = __dependency10__.defer;
}); var config = __dependency11__.config;
window.RSVP = requireModule("rsvp"); var resolve = __dependency12__.resolve;
var reject = __dependency13__.reject;
function configure(name, value) {
config[name] = value;
}
__exports__.CancellationError = CancellationError;
__exports__.Promise = Promise;
__exports__.EventTarget = EventTarget;
__exports__.all = all;
__exports__.any = any;
__exports__.Queue = Queue;
__exports__.ResolvedQueueError = ResolvedQueueError;
__exports__.delay = delay;
__exports__.timeout = timeout;
__exports__.hash = hash;
__exports__.rethrow = rethrow;
__exports__.defer = defer;
__exports__.denodeify = denodeify;
__exports__.configure = configure;
__exports__.resolve = resolve;
__exports__.reject = reject;
});
window.RSVP = requireModule("rsvp");
})(window); })(window);
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>947.51153.11549.27255</string> </value> <value> <string>956.24426.45217.3157</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1450107607.48</float> <float>1484729690.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -135,6 +135,29 @@ define("rsvp/async", ...@@ -135,6 +135,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) {
...@@ -196,6 +219,8 @@ define("rsvp/async", ...@@ -196,6 +219,8 @@ define("rsvp/async",
async = useNextTick(); async = useNextTick();
} else if (BrowserMutationObserver) { } else if (BrowserMutationObserver) {
async = useMutationObserver(); async = useMutationObserver();
} else if (checkNativePromise()) {
async = useNativePromise();
} else { } else {
async = useSetTimeout(); async = useSetTimeout();
} }
......
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