Permalink
Browse files

Update up to changes in es5-ext

  • Loading branch information...
1 parent b149d8e commit 02d7ffe9f8ebb8ce4d683e74bc4593fae4826051 @medikoo committed May 23, 2012
View
@@ -2,13 +2,13 @@
'use strict';
-var every = Array.prototype.every
- , call = Function.prototype.call
- , valid = require('es5-ext/lib/valid-value')
- , isError = require('es5-ext/lib/Error/is-error')
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , deferred = require('../../deferred')
- , isPromise = require('../../is-promise');
+var every = Array.prototype.every
+ , call = Function.prototype.call
+ , valid = require('es5-ext/lib/valid-value')
+ , isError = require('es5-ext/lib/Error/is-error')
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , deferred = require('../../deferred')
+ , isPromise = require('../../is-promise');
var Map = function (list, cb, thisArg, limit) {
this.list = list;
@@ -98,9 +98,7 @@ Map.prototype = {
module.exports = function (cb, thisArg, limit) {
var result, iterator, d;
valid(this);
- if (cb != null) {
- assertCallable(cb);
- }
+ (cb == null) || callable(cb);
every.call(this, (iterator = new Map(this, cb, thisArg, limit)).iterate,
iterator);
iterator.initialized = true;
View
@@ -2,15 +2,15 @@
'use strict';
-var every = Array.prototype.every
- , call = Function.prototype.call
- , valid = require('es5-ext/lib/valid-value')
- , isError = require('es5-ext/lib/Error/is-error')
- , silent = require('es5-ext/lib/Function/prototype/silent')
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , create = require('es5-ext/lib/Object/plain-create')
- , isPromise = require('../../is-promise')
- , promise = require('../../promise');
+var every = Array.prototype.every
+ , call = Function.prototype.call
+ , valid = require('es5-ext/lib/valid-value')
+ , isError = require('es5-ext/lib/Error/is-error')
+ , silent = require('es5-ext/lib/Function/prototype/silent')
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , create = require('es5-ext/lib/Object/plain-create')
+ , isPromise = require('../../is-promise')
+ , promise = require('../../promise');
var proto = {
iterate: function self(value, index) {
@@ -41,16 +41,15 @@ var proto = {
return value;
},
processCb: function (accumulator, index, value) {
- return silent.call(this.cb, accumulator, value, index, this.list);
+ return silent.call(this.cb)(accumulator, value, index, this.list);
}
};
module.exports = function (cb, initial) {
var iterator;
valid(this);
- if (cb != null) {
- assertCallable(cb);
- }
+ (cb == null) || callable(cb);
+
if (initial && isError(initial)) {
return promise(initial);
}
View
@@ -2,19 +2,18 @@
'use strict';
-var silent = require('es5-ext/lib/Function/prototype/silent')
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , deferred = require('../../deferred')
+var silent = require('es5-ext/lib/Function/prototype/silent')
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , deferred = require('../../deferred')
+
, delayed;
delayed = function (fn, args, resolve) {
- resolve(silent.apply(fn.bind(this), args));
+ resolve(silent.call(fn).apply(this, args));
};
module.exports = function (timeout) {
- var fn;
- assertCallable(this);
- fn = this;
+ var fn = callable(this);
return function () {
var d = deferred();
setTimeout(delayed.bind(this, fn, arguments, d.resolve), timeout);
View
@@ -3,13 +3,13 @@
// controlled with qLimit value, any calls that would reach over that limit
// would be discarded (its promise would resolve with "Too many calls" error)
-var apply = Function.prototype.apply
- , max = Math.max
- , toUinteger = require('es5-ext/lib/Number/to-uinteger')
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , deferred = require('../../deferred')
- , isPromise = require('../../is-promise')
- , promise = require('../../promise')
+var apply = Function.prototype.apply
+ , max = Math.max
+ , toUint = require('es5-ext/lib/Number/to-uint')
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , deferred = require('../../deferred')
+ , isPromise = require('../../is-promise')
+ , promise = require('../../promise')
, reject;
@@ -23,9 +23,9 @@ reject = function () {
module.exports = function (cLimit, qLimit) {
var fn, count, decrement, unload, queue, run;
- fn = assertCallable(this) && this;
- cLimit = max(toUinteger(cLimit), 1);
- qLimit = ((qLimit == null) || isNaN(qLimit)) ? Infinity : toUinteger(qLimit);
+ fn = callable(this);
+ cLimit = max(toUint(cLimit), 1);
+ qLimit = ((qLimit == null) || isNaN(qLimit)) ? Infinity : toUint(qLimit);
count = 0;
queue = [];
@@ -2,18 +2,17 @@
'use strict';
-var isArray = Array.isArray
- , slice = Array.prototype.slice
- , some = Array.prototype.some
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , silent = require('es5-ext/lib/Function/prototype/silent')
- , deferred = require('../../deferred')
- , isPromise = require('../../is-promise');
+var isArray = Array.isArray
+ , slice = Array.prototype.slice
+ , some = Array.prototype.some
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , silent = require('es5-ext/lib/Function/prototype/silent')
+ , deferred = require('../../deferred')
+ , isPromise = require('../../is-promise');
module.exports = function (length) {
var fn, args;
- assertCallable(this);
- fn = this;
+ fn = callable(this);
if (length != null) {
length = length >>> 0;
}
@@ -27,7 +26,7 @@ module.exports = function (length) {
return fn.apply(this, isArray(args) ? args : [args]);
}.bind(this));
} else {
- return deferred(silent.apply(fn.bind(this), args));
+ return deferred(silent.call(fn).apply(this, args));
}
};
};
@@ -2,17 +2,16 @@
'use strict';
-var isArray = Array.isArray
- , some = Array.prototype.some
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , apply = require('../utils/apply-async')
- , deferred = require('../../deferred')
- , isPromise = require('../../is-promise');
+var isArray = Array.isArray
+ , some = Array.prototype.some
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , apply = require('../utils/apply-async')
+ , deferred = require('../../deferred')
+ , isPromise = require('../../is-promise');
module.exports = function (length) {
var fn, args;
- assertCallable(this);
- fn = this;
+ fn = callable(this);
if (length != null) {
length = length >>> 0;
}
View
@@ -19,13 +19,13 @@
'use strict';
-var assertCallable = require('es5-ext/lib/Object/assert-callable')
+var callable = require('es5-ext/lib/Object/valid-callable')
, b;
require('../../extend')('cb', function (win, fail) {
- (win != null) && assertCallable(win);
- (fail != null) && assertCallable(fail);
+ (win == null) || callable(win);
+ (fail == null) || callable(fail);
if (win || fail) {
if (this._base.resolved) {
b.apply(this._base, arguments);
@@ -14,7 +14,7 @@ var slice = Array.prototype.slice
, apply;
apply = function (fn, args, resolve) {
- return resolve(silent.apply(fn.bind(this), args));
+ return resolve(silent.call(fn).apply(this, args));
};
require('../../extend')('invoke', [valid],
@@ -2,20 +2,20 @@
'use strict';
-var assertCallable = require('es5-ext/lib/Object/assert-callable')
- , silent = require('es5-ext/lib/Function/prototype/silent')
- , extend = require('../../../extend');
+var callable = require('es5-ext/lib/Object/valid-callable')
+ , silent = require('es5-ext/lib/Function/prototype/silent')
+ , extend = require('../../../extend');
module.exports = function (name, ext) {
extend(name, [function (cb) {
- return (cb != null) && assertCallable(cb);
+ (cb == null) || callable(cb);
}], function (args, resolve) {
var cb, cbs;
if (this.failed) {
return resolve(this.promise);
} else {
- return resolve(silent.call(ext.bind(this.value,
- args[0], args[1], args[2])));
+ return resolve(silent.call(ext).call(this.value,
+ args[0], args[1], args[2]));
}
});
};
View
@@ -10,19 +10,19 @@
'use strict';
-var forEach = Array.prototype.forEach
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , isCallable = require('es5-ext/lib/Object/is-callable')
- , deferred = require('./deferred')
- , promise = require('./promise')
+var forEach = Array.prototype.forEach
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , isCallable = require('es5-ext/lib/Object/is-callable')
+ , deferred = require('./deferred')
+ , promise = require('./promise')
, front = promise.front, back = promise.back;
module.exports = function (name, f, b) {
- (b != null) && assertCallable(b);
+ (b == null) || callable(b);
if (!isCallable(f)) {
f && forEach.call(f, function (validator) {
- (validator != null) && assertCallable(validator);
+ (validator == null) || callable(validator);
});
if (!b) {
throw new Error("No methods provided");
View
@@ -1,12 +1,12 @@
// Run if you want to monitor unresolved promises (in properly working
// application there should be no promises that are never resolved)
-var max = Math.max
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , isCallable = require('es5-ext/lib/Object/is-callable')
- , toUinteger = require('es5-ext/lib/Number/to-uinteger')
- , deferred = require('./deferred')
- , promise = require('./promise');
+var max = Math.max
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , isCallable = require('es5-ext/lib/Object/is-callable')
+ , toUint = require('es5-ext/lib/Number/to-uint')
+ , deferred = require('./deferred')
+ , promise = require('./promise');
exports = module.exports = function (timeout, cb) {
if (timeout === false) {
@@ -16,7 +16,7 @@ exports = module.exports = function (timeout, cb) {
delete exports.callback;
return;
}
- exports.timeout = timeout = max(toUinteger(timeout) || 5000, 50);
+ exports.timeout = timeout = max(toUint(timeout) || 5000, 50);
if (cb == null) {
if ((typeof console !== 'undefined') && console &&
isCallable(console.error)) {
@@ -26,7 +26,7 @@ exports = module.exports = function (timeout, cb) {
};
}
} else {
- assertCallable(cb);
+ callable(cb);
}
exports.callback = cb;
View
@@ -4,26 +4,26 @@
'use strict';
-var push = Array.prototype.push
- , apply = Function.prototype.apply
- , defineProperty = Object.defineProperty
- , keys = Object.keys
- , isError = require('es5-ext/lib/Error/is-error')
- , noop = require('es5-ext/lib/Function/noop')
- , match = require('es5-ext/lib/Function/prototype/match')
- , silent = require('es5-ext/lib/Function/prototype/silent')
- , assertCallable = require('es5-ext/lib/Object/assert-callable')
- , dscr = require('es5-ext/lib/Object/descriptor')
- , isCallable = require('es5-ext/lib/Object/is-callable')
- , isPromise = require('./is-promise')
+var push = Array.prototype.push
+ , apply = Function.prototype.apply
+ , defineProperty = Object.defineProperty
+ , keys = Object.keys
+ , isError = require('es5-ext/lib/Error/is-error')
+ , noop = require('es5-ext/lib/Function/noop')
+ , match = require('es5-ext/lib/Function/prototype/match')
+ , silent = require('es5-ext/lib/Function/prototype/silent')
+ , callable = require('es5-ext/lib/Object/valid-callable')
+ , dscr = require('es5-ext/lib/Object/descriptor')
+ , isCallable = require('es5-ext/lib/Object/is-callable')
+ , isPromise = require('./is-promise')
, front, back, Resolved, Unresolved, deferred, createPromise;
// Front for main promise extensions. This methods are called at invocation
front = {
end: function (win, fail) {
- (win != null) && assertCallable(win);
- (fail != null) && assertCallable(fail);
+ (win == null) || callable(win);
+ (fail == null) || callable(fail);
this._base.next('end', arguments);
},
valueOf: function () {
@@ -37,7 +37,7 @@ back = {
then: function (win, fail, resolve) {
var cb = this.failed ? fail : win;
return resolve((cb == null) ? this.promise :
- (isCallable(cb) ? silent.call(cb, this.value) : cb));
+ (isCallable(cb) ? silent.call(cb)(this.value) : cb));
},
end: function (win, fail) {
if (this.failed) {
@@ -66,7 +66,7 @@ Resolved.prototype = {
resolved: true,
link: function (promise) {
var previous, base;
- base = dscr.v(this);
+ base = dscr('', this);
previous = promise._base;
this.promise = promise;
defineProperty(promise, '_base', base);
@@ -97,7 +97,7 @@ Unresolved.prototype = {
resolved: false,
link: function (promise) {
var previous, base;
- base = dscr.c(this);
+ base = dscr('c', this);
if ((previous = promise._base)) {
clearTimeout(previous.timeout);
if (previous.monitor) {

0 comments on commit 02d7ffe

Please sign in to comment.