[Pkg-javascript-commits] [dojo] 26/88: Improve handling of progback results

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.8.5
in repository dojo.

commit e147d7d406d341390fa63cb26ea8caf9bc0a16dc
Author: Colin Snover <github.com at zetafleet.com>
Date:   Wed Sep 26 22:21:14 2012 +0000

     Improve handling of progback results
    
    * Don't resolve the returned promise
    * If the progback returns a value, emit that value on the returned promise as a progress update, allowing for easier update propagation
    
    Fixes #15996, !strict
    Backport to 1.8.
    
    
    git-svn-id: http://svn.dojotoolkit.org/src/branches/1.8/dojo@29736 560b804f-0ae3-0310-86f3-f6aa0a117693
---
 Deferred.js       | 24 +++++++++++++++---------
 tests/Deferred.js | 23 ++++++++++++++++++++---
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/Deferred.js b/Deferred.js
index ee1c36b..79d61f7 100644
--- a/Deferred.js
+++ b/Deferred.js
@@ -35,16 +35,22 @@ define([
 		if(func){
 			try{
 				var newResult = func(result);
-				if(newResult && typeof newResult.then === "function"){
-					listener.cancel = newResult.cancel;
-					newResult.then(
-							// Only make resolvers if they're actually going to be used
-							makeDeferredSignaler(deferred, RESOLVED),
-							makeDeferredSignaler(deferred, REJECTED),
-							makeDeferredSignaler(deferred, PROGRESS));
-					return;
+				if(type === PROGRESS){
+					if(typeof newResult !== "undefined"){
+						signalDeferred(deferred, type, newResult);
+					}
+				}else{
+					if(newResult && typeof newResult.then === "function"){
+						listener.cancel = newResult.cancel;
+						newResult.then(
+								// Only make resolvers if they're actually going to be used
+								makeDeferredSignaler(deferred, RESOLVED),
+								makeDeferredSignaler(deferred, REJECTED),
+								makeDeferredSignaler(deferred, PROGRESS));
+						return;
+					}
+					signalDeferred(deferred, RESOLVED, newResult);
 				}
-				signalDeferred(deferred, RESOLVED, newResult);
 			}catch(error){
 				signalDeferred(deferred, REJECTED, error);
 			}
diff --git a/tests/Deferred.js b/tests/Deferred.js
index d41ec1d..d1b8c31 100644
--- a/tests/Deferred.js
+++ b/tests/Deferred.js
@@ -182,11 +182,12 @@ define([
 
 		"progress() results are not cached": function(t){
 			var obj1 = {}, obj2 = {};
-			var received;
+			var received = [];
 			this.deferred.progress(obj1);
-			this.deferred.then(null, null, function(result){ received = result; });
+			this.deferred.then(null, null, function(result){ received.push(result); });
 			this.deferred.progress(obj2);
-			t.t(received === obj2);
+			t.t(received[0] === obj2);
+			t.is(1, received.length);
 		},
 
 		"progress() with chaining": function(t){
@@ -199,6 +200,14 @@ define([
 			t.t(received === obj);
 		},
 
+		"after progress(), the progback return value is emitted on the returned promise": function(t){
+			var received;
+			var promise = this.deferred.then(null, null, function(n){ return n * n; });
+			promise.then(null, null, function(n){ received = n; });
+			this.deferred.progress(2);
+			t.is(4, received);
+		},
+
 		"progress() is already bound to the deferred": function(t){
 			var obj = {};
 			var received;
@@ -438,6 +447,14 @@ define([
 			then(function(result){ received = result; });
 			this.deferred.resolve(obj);
 			t.t(received === obj);
+		},
+
+		"then() with progback: returned promise is not fulfilled when progress is emitted": function(t){
+			var progressed = false;
+			var promise = this.deferred.then(null, null, function(){ progressed = true; });
+			this.deferred.progress();
+			t.t(progressed, "Progress was received.");
+			t.f(promise.isFulfilled(), "Promise is not fulfilled.");
 		}
 	};
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list