From f4efff6f49dab6fe1c4dc39a4ce98a2a13840ce7 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 7 Aug 2015 23:34:14 +0500 Subject: [PATCH] lodash: changed _.once() method --- lodash/lodash-tests.ts | 7 ++++--- lodash/lodash.d.ts | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 53a316ab50..dbfb627715 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -958,9 +958,10 @@ result = _.negate(testN result = _(testNegatePredicate).negate().value(); result = _(testNegatePredicate).negate().value(); -var initialize = _.once(function () { }); -initialize(); -initialize(); +// _.once +result = <() => void>_.once<() => void>(function () {}); +result = <() => void>(_(function () {}).once().value()); + var returnedOnce = _.throttle(function (a: any) { return a * 5; }, 5); returnedOnce(4); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ea93f2e70c..868c133d20 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5616,15 +5616,22 @@ declare module _ { //_.once interface LoDashStatic { /** - * Creates a function that is restricted to execute func once. Repeat calls to the function - * will return the value of the first call. The func is executed with the this binding of the - * created function. - * @param func Function to only execute once. - * @return The new restricted function. - **/ + * Creates a function that is restricted to invoking func once. Repeat calls to the function return the value + * of the first call. The func is invoked with the this binding and arguments of the created function. + * @param func The function to restrict. + * @return Returns the new restricted function. + */ + once(func: T): T; } + interface LoDashObjectWrapper { + /** + * @see _.once + */ + once(): LoDashObjectWrapper; + } + //_.partial interface LoDashStatic { /**