/
function-call.ts
85 lines (73 loc) · 2.87 KB
/
function-call.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @module parallel
*/
/** */
import {IFunctionId} from "./function-id";
import {ISerializedFunctionCall} from "./serialized-function-call";
/**
* Represents a function call
*/
export class FunctionCall {
/**
* Creates a new function call for a function without any arguments
* @param func the function to call
* @returns the function call
*/
public static create(func: () => any): FunctionCall;
/**
* Creates a new function call to a function accepting a single argument
* @param func the function to call
* @param param1 the single parameter passed to the function
* @param TParam1 type of the single parameter
* @returns the function call
*/
public static create<TParam1>(func: (arg1: TParam1) => any, param1: TParam1): FunctionCall;
/**
* Creates a new function call to a function passing the given parameters
* @param func the function to call
* @param param1 the first parameter to pass to the function
* @param param2 the second parameter to pass to the function
* @param TParam1 type of the first parameter
* @param TParam2 type of the second parameter
* @returns the function call
*/
public static create<TParam1, TParam2>(func: (arg1: TParam1, arg2: TParam2) => any, param1: TParam1, param2: TParam2): FunctionCall;
/**
* @param param3 the third parameter to pass to the function
* @param TParam3 the type of the third parameter
*/
public static create<TParam1, TParam2, TParam3>(func: (arg1: TParam1, arg2: TParam2, arg3: TParam3) => any, param1: TParam1, param2: TParam2, param3: TParam3): FunctionCall;
public static create(func: IFunctionId, ...params: any[]): FunctionCall;
public static create(func: IFunctionId | ((...args: any[]) => any), ...args: any[]): FunctionCall {
return new FunctionCall(func, args);
}
/**
* Creates a function call for a function with with many arguments
* @param func the function to call
* @param params the parameters to pass
* @returns the function call
*/
public static createUnchecked(func: Function | IFunctionId, ...params: any[]) {
return new FunctionCall(func, params);
}
/**
* Creates a function call instance from its serialized representation
* @param serialized the serialized function call
* @returns {FunctionCall} the function call
*/
public static fromSerialized(serialized: ISerializedFunctionCall): FunctionCall {
return new FunctionCall(serialized.functionId, serialized.parameters);
}
/**
* The function to call
*/
public func: Function | IFunctionId;
/**
* The parameters to pass to the function when calling it
*/
public params: any[];
private constructor(func: Function | IFunctionId, params: any[]) {
this.func = func;
this.params = params;
}
}