added _.wrap definition, fixed bugs in tests, removed duplicate/old tests

This commit is contained in:
Brian Zengel
2013-10-19 00:44:52 -04:00
parent 8d81eeba61
commit ad3b58c6e7
2 changed files with 18 additions and 52 deletions
+7 -31
View File
@@ -501,13 +501,19 @@ var optionsPartialRight = {
defaultsDeep(optionsPartialRight, _.templateSettings);
var throttled = _.throttle(updatePosition, 100);
var throttled = _.throttle(function () { }, 100);
jQuery(window).on('scroll', throttled);
jQuery('.interactive').on('click', _.throttle(function() { }, 300000, {
'trailing': false
}));
var helloWrap = function(name) { return 'hello ' + name; };
var helloWrap2 = _.wrap(helloWrap, function(func) {
return 'before, ' + func('moe') + ', after';
});
helloWrap2();
@@ -559,36 +565,6 @@ _.merge(mergeFood, mergeOtherFood, function(a, b) {
///////////////////////////////////////////////////////////////////////////////////////
var updatePosition = () => alert('updating position...');
var throttled = _.throttle(updatePosition, 100);
$(window).scroll(throttled);
var createApplication = () => alert('creating application...');
var initialize = _.once(createApplication);
initialize();
initialize();
// var notes: any[];
// var render = () => alert("rendering...");
// var renderNotes = _.after(notes.length, render);
// _.each(notes, (note) => note.asyncSave({ success: renderNotes }));
var hello = function (name) { return "hello: " + name; };
// can't use the same "hello" var otherwise typescript fails
var hello2 = _.wrap(hello, (func) => { return "before, " + func("moe") + ", after"; });
hello2();
var greet = function (name) { return "hi: " + name; };
var exclaim = function (statement) { return statement + "!"; };
var welcome = _.compose(exclaim, greet);
welcome('moe');
///////////////////////////////////////////////////////////////////////////////////////
_.keys({ one: 1, two: 2, three: 3 });
_.values({ one: 1, two: 2, three: 3 });
_.pairs({ one: 1, two: 2, three: 3 });
+11 -21
View File
@@ -1925,7 +1925,17 @@ declare module _ {
wait: number,
options?: ThrottleSettings): Function;
/**
* Creates a function that provides value to the wrapper function as its first argument.
* Additional arguments provided to the function are appended to those provided to the
* wrapper function. The wrapper is executed with the this binding of the created function.
* @param value The value to wrap.
* @param wrapper The wrapper function.
* @return The new function.
**/
export function wrap(
value: any,
wrapper: (func: Function, ...args: any[]) => any): Function;
@@ -2089,26 +2099,6 @@ declare module _ {
/**
* Wraps the first function inside of the wrapper function, passing it as the first argument. This allows
* the wrapper to execute code before and after the function runs, adjust the arguments, and execute it
* conditionally.
* @param fn Function to wrap.
* @param wrapper The function that will wrap `fn`.
* @return Wrapped version of `fn.
**/
export function wrap(
fn: Function,
wrapper: (fn: Function, ...args: any[]) => any): Function;