Comparing version 0.2.4 to 0.2.5
@@ -53,2 +53,4 @@ // vim:ts=4:sts=4:sw=4: | ||
var DUCK = "promiseSend"; | ||
var enqueue; | ||
@@ -65,16 +67,2 @@ try { | ||
var print; | ||
if (typeof console !== "undefined") { | ||
// browsers in debug mode, Node | ||
print = function (message) { | ||
console.log(message); | ||
}; | ||
} else if (typeof require !== "undefined") { | ||
// Narwhal | ||
print = require("system").print; | ||
} else { | ||
// browsers otherwise | ||
print = function () {} | ||
} | ||
// useful for an identity stub and default resolvers | ||
@@ -119,3 +107,3 @@ function identity (x) {return x} | ||
promise.emit = function () { | ||
promise[DUCK] = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
@@ -179,3 +167,3 @@ if (pending) { | ||
promise.emit = function (op, resolved /* ...args */) { | ||
promise[DUCK] = function (op, resolved /* ...args */) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
@@ -213,3 +201,3 @@ var result; | ||
function isPromise(object) { | ||
return object instanceof Promise; | ||
return object && typeof object[DUCK] === "function"; | ||
}; | ||
@@ -283,6 +271,6 @@ | ||
"put": function (name, value) { | ||
object[name] = value; | ||
return object[name] = value; | ||
}, | ||
"del": function (name) { | ||
delete object[name]; | ||
return delete object[name]; | ||
}, | ||
@@ -351,3 +339,3 @@ "post": function (name /*...args*/) { | ||
done = true; | ||
deferred.resolve(ref(value).emit("when", resolved, rejected)); | ||
deferred.resolve(ref(value)[DUCK]("when", resolved, rejected)); | ||
}, function (reason) { | ||
@@ -488,9 +476,9 @@ if (done) | ||
*/ | ||
function forward(promise /*, op, resolved, ... */) { | ||
function forward(promise, op, resolved /* ... */) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
enqueue(function () { | ||
try { | ||
promise.emit.apply(promise, args); | ||
promise[DUCK].apply(promise, args); | ||
} catch (exception) { | ||
print(exception.stack || exception); | ||
resolved(reject(exception)); | ||
} | ||
@@ -497,0 +485,0 @@ }); |
{ | ||
"name": "q", | ||
"description": "defer/when-style promises (CommonJS/Promises/B)", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "http://github.com/kriskowal/q/", | ||
@@ -6,0 +6,0 @@ "author": "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)", |
@@ -65,5 +65,5 @@ // vim:ts=4:sts=4:sw=4: | ||
Q.when(Q.post(d.promise, 'a', [1]), function (result) { | ||
ASSERT.equal(result, 2, 'correct value is returned by post'); | ||
ASSERT.equal(value._a, 1, 'post invoked function as expected'); | ||
Q.when(Q.post(d.promise, 'a', 1), function (result) { | ||
ASSERT.ok(result === 2, 'correct value is returned by post'); | ||
ASSERT.ok(value._a === 1, 'post invoked function as expected'); | ||
done(); | ||
@@ -81,3 +81,3 @@ }, function (reason) { | ||
Q.when(Q.post(d.promise, 'a', [1]), function (result) { | ||
Q.when(Q.post(d.promise, 'a', 1), function (result) { | ||
ASSERT.fail('Unxpeced to call non-existing method:' + result); | ||
@@ -84,0 +84,0 @@ done(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
76250
29
1482