From 11b9af412536f1cee2036302955de1f2547dce0a Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 22:10:22 -0400 Subject: [PATCH] added _.after definition --- lodash/lodash-tests.ts | 20 ++++- lodash/lodash.d.ts | 163 ++++++++++++++++++++--------------------- 2 files changed, 97 insertions(+), 86 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index dabbd6b4c..07a88d1d0 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -379,7 +379,19 @@ result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); result = _.where(stoogesCombined, { 'age': 40 }); result = _.where(stoogesCombined, { 'quotes': ['Poifect!'] }); +/************* + * Functions * + *************/ +var saves = ['profile', 'settings']; +var asyncSave = (obj) => obj.done(); +var done = _.after(saves.length, function() { + console.log('Done saving!'); +}); + +_.forEach(saves, function(type) { + asyncSave({ 'type': type, 'complete': done }); +}); @@ -464,10 +476,10 @@ 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 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 diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f9fee5695..35417b1aa 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1691,80 +1691,89 @@ declare module _ { list: Collection, properties: U): T[]; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /************* * Functions * *************/ + + /** + * Creates a function that executes func, with the this binding and arguments of the + * created function, only after being called n times. + * @param n The number of times the function must be called before func is executed. + * @param func The function to restrict. + * @return The new restricted function. + **/ + export function after( + n: number, + func: Function): Function; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /** * Bind a function to an object, meaning that whenever the function is called, the value of this will @@ -1893,17 +1902,7 @@ declare module _ { **/ export function once(fn: Function): Function; - /** - * Creates a version of the function that will only be run after first being called count times. Useful - * for grouping asynchronous responses, where you want to be sure that all the async calls have finished, - * before proceeding. - * @param count Number of times to be called before actually executing. - * @fn The function to defer execution `count` times. - * @return Copy of `fn` that will not execute until it is invoked `count` times. - **/ - export function after( - count: number, - fn: Function): Function; + /** * Wraps the first function inside of the wrapper function, passing it as the first argument. This allows