8000 Make `_.defer` use `setImmediate` if available. · lodash/lodash@5133e39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5133e39

Browse files
committed
Make _.defer use setImmediate if available.
Former-commit-id: b3898d78725a4b203856916b1b071ab9c6f40b83
1 parent cb3b4e4 commit 5133e39

File tree

8 files changed

+99
-86
lines changed

8 files changed

+99
-86
lines changed

dist/lodash.compat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,10 +4224,10 @@
42244224
* _.defer(function() { alert('deferred'); });
42254225
* // returns from the function before `alert` is called
42264226
*/
4227-
function defer(func) {
4227+
var defer = reNative.test(window.setImmediate) && bind(setImmediate, window) || function(func) {
42284228
var args = slice(arguments, 1);
42294229
return setTimeout(function() { func.apply(undefined, args); }, 1);
4230-
}
4230+
};
42314231

42324232
/**
42334233
* Creates a function that memoizes the result of `func`. If `resolver` is

dist/lodash.compat.min.js

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lodash.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
'\n } ';
293293
} else {
294294
__p += '\n for (index in iterable) {';
295-
if ( obj.useHas) {
295+
if (obj.useHas) {
296296
__p += '\n if (';
297297
if (obj.useHas) {
298298
__p += 'hasOwnProperty.call(iterable, index)';
@@ -302,7 +302,7 @@
302302
__p +=
303303
(obj.loop ) +
304304
'; ';
305-
if ( obj.useHas) {
305+
if (obj.useHas) {
306306
__p += '\n }';
307307
} ;
308308
__p += '\n } ';
@@ -4074,10 +4074,10 @@
40744074
* _.defer(function() { alert('deferred'); });
40754075
* // returns from the function before `alert` is called
40764076
*/
4077-
function defer(func) {
4077+
var defer = reNative.test(window.setImmediate) && bind(setImmediate, window) || function(func) {
40784078
var args = slice(arguments, 1);
40794079
return setTimeout(function() { func.apply(undefined, args); }, 1);
4080-
}
4080+
};
40814081

40824082
/**
40834083
* Creates a function that memoizes the result of `func`. If `resolver` is

dist/lodash.min.js

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lodash.underscore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,10 +3463,10 @@
34633463
* _.defer(function() { alert('deferred'); });
34643464
* // returns from the function before `alert` is called
34653465
*/
3466-
function defer(func) {
3466+
var defer = reNative.test(window.setImmediate) && bind(setImmediate, window) || function(func) {
34673467
var args = slice(arguments, 1);
34683468
return setTimeout(function() { func.apply(undefined, args); }, 1);
3469-
}
3469+
};
34703470

34713471
/**
34723472
* Creates a function that memoizes the result of `func`. If `resolver` is

dist/lodash.underscore.min.js

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lodash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,10 +4231,10 @@
42314231
* _.defer(function() { alert('deferred'); });
42324232
* // returns from the function before `alert` is called
42334233
*/
4234-
function defer(func) {
4234+
var defer = reNative.test(window.setImmediate) && bind(setImmediate, window) || function(func) {
42354235
var args = slice(arguments, 1);
42364236
return setTimeout(function() { func.apply(undefined, args); }, 1);
4237-
}
4237+
};
42384238

42394239
/**
42404240
* Creates a function that memoizes the result of `func`. If `resolver` is

test/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,19 @@
545545

546546
/*--------------------------------------------------------------------------*/
547547

548+
QUnit.module('lodash.defer');
549+
550+
(function() {
551+
asyncTest('should accept additional arguments', function() {
552+
_.defer(function() {
553+
deepEqual(slice.call(arguments), [1, 2, 3]);
554+
QUnit.start();
555+
}, 1, 2, 3);
556+
});
557+
}());
558+
559+
/*------------------------------------------------------ 4E2F --------------------*/
560+
548561
QUnit.module('lodash.difference');
549562

550563
(function() {

0 commit comments

Comments
 (0)
0