Skip to content

Commit

Permalink
Add warnings for deprecated methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Forbes Lindesay authored and domenic committed May 26, 2012
1 parent 27256cb commit 8341cd1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ if (Error.captureStackTrace) {
})();
}

function deprecate(fn, name, alternative){
return function () {
if (typeof console !== "undefined" && typeof console.warn === "function"){
console.warn(name + " is deprecated, use " + alternative + " instead.");
}
return fn.apply(fn,arguments);
};
}

// end of shims
// beginning of real work
Expand Down Expand Up @@ -485,7 +493,6 @@ function defer() {
* promise.
* @returns a nodeback
*/
defer.prototype.node = // XXX deprecated
defer.prototype.makeNodeResolver = function () {
var self = this;
return function (error, value) {
Expand All @@ -498,6 +505,8 @@ defer.prototype.makeNodeResolver = function () {
}
};
};
// XXX deprecated
defer.prototype.node = deprecate(defer.prototype.makeNodeResolver, "node", "makeNodeResolver");

/**
* @param makePromise {Function} a function that returns nothing and accepts
Expand Down Expand Up @@ -708,7 +717,7 @@ function reject(exception) {
*/
exports.begin = resolve; // XXX experimental
exports.resolve = resolve;
exports.ref = resolve; // XXX deprecated, use resolve
exports.ref = deprecate(resolve, "ref", "resolve"); // XXX deprecated, use resolve
function resolve(object) {
// If the object is already a Promise, return it directly. This enables
// the resolve function to both be used to created references from objects,
Expand Down Expand Up @@ -991,8 +1000,8 @@ function _return(value) {
* Constructs a promise method that can be used to safely observe resolution of
* a promise for an arbitrarily named method like "propfind" in a future turn.
*/
exports.sender = sender; // XXX deprecated, use dispatcher
exports.Method = sender; // XXX deprecated, use dispatcher
exports.sender = deprecate(sender, "sender", "dispatcher"); // XXX deprecated, use dispatcher
exports.Method = deprecate(sender, "Method", "dispatcher"); // XXX deprecated, use dispatcher
function sender(op) {
return function (object) {
var args = array_slice(arguments, 1);
Expand All @@ -1007,7 +1016,7 @@ function sender(op) {
* @param ...args further arguments to be forwarded to the operation
* @returns result {Promise} a promise for the result of the operation
*/
exports.send = send; // XXX deprecated, use dispatch
exports.send = deprecate(send, "send", "dispatch"); // XXX deprecated, use dispatch
function send(object, op) {
var deferred = defer();
var args = array_slice(arguments, 2);
Expand Down Expand Up @@ -1114,7 +1123,8 @@ exports.invoke = function (value, name) {
* @param thisp the `this` object for the call
* @param args array of application arguments
*/
var apply = exports.apply = dispatcher("apply"); // XXX deprecated, use fapply
// XXX deprecated, use fapply
var apply = exports.apply = deprecate(dispatcher("apply"), "apply", "fapply");

/**
* Applies the promised function in a future turn.
Expand All @@ -1129,7 +1139,8 @@ var fapply = exports.fapply = dispatcher("fapply");
* @param thisp the `this` object for the call
* @param ...args array of application arguments
*/
exports.call = call; // XXX deprecated, use fcall
// XXX deprecated, use fcall
exports.call = deprecate(call, "call", "fcall");
function call(value, thisp) {
var args = array_slice(arguments, 2);
return apply(value, thisp, args);
Expand All @@ -1154,7 +1165,7 @@ function fcall(value) {
* @param thisp the `this` object for the call
* @param ...args array of application arguments
*/
exports.bind = bind; // XXX deprecated, use fbind
exports.bind = deprecate(bind, "bind", "fbind"); // XXX deprecated, use fbind
function bind(value, thisp) {
var args = array_slice(arguments, 2);
return function bound() {
Expand Down

0 comments on commit 8341cd1

Please sign in to comment.