From f0cfe83e3725f9a3928da97a6e3085e79cb25309 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 18 Mar 2013 10:26:24 +0400 Subject: upgrade dojo to 1.8.3 (refs #570) --- lib/dojo/promise/tracer.js.uncompressed.js | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/dojo/promise/tracer.js.uncompressed.js (limited to 'lib/dojo/promise/tracer.js.uncompressed.js') diff --git a/lib/dojo/promise/tracer.js.uncompressed.js b/lib/dojo/promise/tracer.js.uncompressed.js new file mode 100644 index 000000000..b5380cc32 --- /dev/null +++ b/lib/dojo/promise/tracer.js.uncompressed.js @@ -0,0 +1,85 @@ +define("dojo/promise/tracer", [ + "../_base/lang", + "./Promise", + "../Evented" +], function(lang, Promise, Evented){ + "use strict"; + + // module: + // dojo/promise/tracer + + /*===== + return { + // summary: + // Trace promise fulfillment. + // description: + // Trace promise fulfillment. Calling `.trace()` or `.traceError()` on a + // promise enables tracing. Will emit `resolved`, `rejected` or `progress` + // events. + + on: function(type, listener){ + // summary: + // Subscribe to traces. + // description: + // See `dojo/Evented#on()`. + // type: String + // `resolved`, `rejected`, or `progress` + // listener: Function + // The listener is passed the traced value and any arguments + // that were used with the `.trace()` call. + } + }; + =====*/ + + var evented = new Evented; + var emit = evented.emit; + evented.emit = null; + // Emit events asynchronously since they should not change the promise state. + function emitAsync(args){ + setTimeout(function(){ + emit.apply(evented, args); + }, 0); + } + + Promise.prototype.trace = function(){ + // summary: + // Trace the promise. + // description: + // Tracing allows you to transparently log progress, + // resolution and rejection of promises, without affecting the + // promise itself. Any arguments passed to `trace()` are + // emitted in trace events. See `dojo/promise/tracer` on how + // to handle traces. + // returns: dojo/promise/Promise + // The promise instance `trace()` is called on. + + var args = lang._toArray(arguments); + this.then( + function(value){ emitAsync(["resolved", value].concat(args)); }, + function(error){ emitAsync(["rejected", error].concat(args)); }, + function(update){ emitAsync(["progress", update].concat(args)); } + ); + return this; + }; + + Promise.prototype.traceRejected = function(){ + // summary: + // Trace rejection of the promise. + // description: + // Tracing allows you to transparently log progress, + // resolution and rejection of promises, without affecting the + // promise itself. Any arguments passed to `trace()` are + // emitted in trace events. See `dojo/promise/tracer` on how + // to handle traces. + // returns: dojo/promise/Promise + // The promise instance `traceRejected()` is called on. + + var args = lang._toArray(arguments); + this.otherwise(function(error){ + emitAsync(["rejected", error].concat(args)); + }); + return this; + }; + + return evented; +}); -- cgit v1.2.3