I have base classes which I transfer swagger generated service methods as function parameters. However, the transpiled service code loses the this scope. In order to keep the correct this scope, the swagger methods should be implemented as fat-arrow functions.
Is there any possibility to generate fat arrow functions?
Version 2.3.0
// correct
public getFindAllCustomerPaged = (page?: string, size?: string, sort?: string, extraHttpRequestParams?: any): Observable<PagedCustomerResources> => {
return this.getFindAllCustomerPagedWithHttpInfo(page, size, sort, extraHttpRequestParams)
.map((response: Response) => {
...
});
}
// loses the this scope if method is hand over function parameter to other objects
public getFindAllCustomerPaged (page?: string, size?: string, sort?: string, extraHttpRequestParams?: any): Observable<PagedCustomerResources> {
return this.getFindAllCustomerPagedWithHttpInfo(page, size, sort, extraHttpRequestParams)
.map((response: Response) => {
...
});
}
cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx
To make sure I understand the problem correctly:
You have some method a which accepts swagger.getFindAllCustomerPaged as a parameter. If you pass it with a(swagger.getFindAllCustomerPaged), getFindAllCustomerPaged looses the this scope. This could be solved either like you proposed or by using a(swagger.getFindAllCustomerPaged.bind(swagger)).
Is my understanding of the issue correct?
@tifu I was just about to respond with that solution haha
On Tue, Oct 17, 2017, 7:26 PM Tino Fuhrmann notifications@github.com
wrote:
To make sure I understand the problem correctly:
You have some method a which accepts swagger.getFindAllCustomerPaged as a
parameter. If you pass it with a(swagger.getFindAllCustomerPaged),
getFindAllCustomerPaged looses the this scope. This could be solved
either like you proposed or by using
a(swagger.getFindAllCustomerPaged.bind(swagger)).
Is my understanding of the issue correct?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/swagger-api/swagger-codegen/issues/6714#issuecomment-337407512,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMPLteIxqruP8xKZ4K5z-jyxm5k4Jjguks5stTeugaJpZM4P7o7s
.
@wurmrobert we probably won't generate fat arrow functions in the future as
@tifu's proposed solution does everything I think you need. Also generating
fat arrow breaks aot I'm some cases and we wouldn't want that!
On Tue, Oct 17, 2017, 7:27 PM Kenneth Steward keni.steward@gmail.com
wrote:
@tifu I was just about to respond with that solution haha
On Tue, Oct 17, 2017, 7:26 PM Tino Fuhrmann notifications@github.com
wrote:To make sure I understand the problem correctly:
You have some method a which accepts swagger.getFindAllCustomerPaged as
a parameter. If you pass it with a(swagger.getFindAllCustomerPaged),
getFindAllCustomerPaged looses the this scope. This could be solved
either like you proposed or by using
a(swagger.getFindAllCustomerPaged.bind(swagger)).
Is my understanding of the issue correct?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/swagger-api/swagger-codegen/issues/6714#issuecomment-337407512,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMPLteIxqruP8xKZ4K5z-jyxm5k4Jjguks5stTeugaJpZM4P7o7s
.
The bind function is the perfect solution to my problem. Many thanks for your help!
Thanks to @TiFu
Most helpful comment
@wurmrobert we probably won't generate fat arrow functions in the future as
@tifu's proposed solution does everything I think you need. Also generating
fat arrow breaks aot I'm some cases and we wouldn't want that!
On Tue, Oct 17, 2017, 7:27 PM Kenneth Steward keni.steward@gmail.com
wrote: