Currently, I am exploring the implementation of the builder pattern and trying to create functions that support optional parameters as arguments. Here is an example of how I am approaching this:
new Service().OnAction(Actions.Add, () => { alert(1); })
.OnAction(Actions.Subtract, () => { alert(1); })
.ServiceBuilder(serviceOptions);
new Service().OnAction(Actions.Add, (vm, container) => {
vm.FirstName = container.find("data-id=FirstName").val();
vm.LastName = container.find("data-id=LastName").val();
})
.OnAction(Actions.Subtract, (vm, container) => { alert(1); })
.ServiceBuilder(serviceOptions);
The code above represents some of my attempts in incorporating this feature.
public OnAction(actions: Actions, x: (y?:any, z?:any) => void) {
if (y != undefined && z != undefined) {
x(y, z);
}
else
x();
return this;
}
I have also referred to the following documentation for additional insights: https://www.typescriptlang.org/docs/handbook/functions.html