Merge pull request #7462 from chrootsu/lodash-bindKey

lodash: signatures of _.bindKey have been changed
This commit is contained in:
Masahiro Wakame
2016-01-10 01:26:33 +09:00
2 changed files with 123 additions and 31 deletions

View File

@@ -5372,24 +5372,87 @@ module TestBindAll {
}
}
var objectBindKey = {
'name': 'moe',
'greet': function (greeting: string) {
return greeting + ' ' + this.name;
// _.bindKey
module TestBindKey {
let object: {
foo: (a: number, b: string) => boolean;
}
};
var funcBindKey: Function = _.bindKey(objectBindKey, 'greet', 'hi');
funcBindKey();
{
type SampleResult = (a: number, b: string) => boolean;
objectBindKey.greet = function (greeting) {
return greeting + ', ' + this.name + '!';
};
let result: SampleResult;
funcBindKey();
result = _.bindKey<Object, SampleResult>(object, 'foo');
result = _.bindKey<SampleResult>(object, 'foo');
}
funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value();
funcBindKey();
{
type SampleResult = (b: string) => boolean;
let result: SampleResult;
result = _.bindKey<Object, SampleResult>(object, 'foo', 42);
result = _.bindKey<SampleResult>(object, 'foo', 42);
}
{
type SampleResult = () => boolean;
let result: SampleResult;
result = _.bindKey<Object, SampleResult>(object, 'foo', 42, '');
result = _.bindKey<SampleResult>(object, 'foo', 42, '');
}
{
type SampleResult = (a: number, b: string) => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(object).bindKey<SampleResult>('foo');
}
{
type SampleResult = (b: string) => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(object).bindKey<SampleResult>('foo', 42);
}
{
type SampleResult = () => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(object).bindKey<SampleResult>('foo', 42, '');
}
{
type SampleResult = (a: number, b: string) => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(object).chain().bindKey<SampleResult>('foo');
}
{
type SampleResult = (b: string) => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(object).chain().bindKey<SampleResult>('foo', 42);
}
{
type SampleResult = () => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(object).chain().bindKey<SampleResult>('foo', 42, '');
}
}
// _.compose
module TestCompose {

65
lodash/lodash.d.ts vendored
View File

@@ -8785,30 +8785,59 @@ declare module _ {
}
//_.bindKey
interface FunctionBindKey {
placeholder: any;
<T extends Object, TResult extends Function>(
object: T,
key: any,
...partials: any[]
): TResult;
<TResult extends Function>(
object: Object,
key: any,
...partials: any[]
): TResult;
}
interface LoDashStatic {
/**
* Creates a function that, when called, invokes the method at object[key] and prepends any
* additional bindKey arguments to those provided to the bound function. This method differs
* from _.bind by allowing bound functions to reference methods that will be redefined or don't
* yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern.
* @param object The object the method belongs to.
* @param key The key of the method.
* @param args Arguments to be partially applied.
* @return The new bound function.
**/
bindKey<T>(
object: T,
key: string,
...args: any[]): Function;
* Creates a function that invokes the method at object[key] and prepends any additional _.bindKey arguments
* to those provided to the bound function.
*
* This method differs from _.bind by allowing bound functions to reference methods that may be redefined
* or dont yet exist. See Peter Michauxs article for more details.
*
* The _.bindKey.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder
* for partially applied arguments.
*
* @param object The object the method belongs to.
* @param key The key of the method.
* @param partials The arguments to be partially applied.
* @return Returns the new bound function.
*/
bindKey: FunctionBindKey;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.bindKey
**/
bindKey(
key: string,
...args: any[]): LoDashImplicitObjectWrapper<Function>;
* @see _.bindKey
*/
bindKey<TResult extends Function>(
key: any,
...partials: any[]
): LoDashImplicitObjectWrapper<TResult>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.bindKey
*/
bindKey<TResult extends Function>(
key: any,
...partials: any[]
): LoDashExplicitObjectWrapper<TResult>;
}
//_.compose