fix (webapp): Add method without 'set_' prefix in generated js

We already do this for 'get_' prefixes
This commit is contained in:
John Colvin committed 2022-09-21 00:17:31 -05:00
1 parent 6142a08db6
commit 54dc7bf6c3
1 file changed
+25 -10
+25 -10
View File
@@ -95,18 +95,33 @@ export class DynamicService {
streams : Array<[string,number,string]>) {
const svc = { context, name, qualifier }
// HACK ALERT: Method prefixes 'get_' and 'set_' seem to be ignored by fable bindings. This
// was observed in IAdminService.get_filtered_admin_data, IAdminService.get_admin_data, and
// IMarginService.set_cash_factor. Calls to those methods (from fsharp) failed in javascript
// due to undefined methods 'filtered_admin_data', 'admin_data', and 'cash_factor'
// respectively. Adding the methods with the prefix removed seems to fix the problem.
//
// WARNING: This hack assumes services won't have methods get_<foo> and set_<foo> (if both
// are present, one of them will be overwritten).
//
// TODO: Replace this hack with a stable solution.
let strip_prefix = (prefix:string) => {
if (!methodName.startsWith(prefix)) {
return false
}
let without_prefix = methodName.substring(prefix.length)
if (without_prefix in this) {
throw new Error(
`The method '${without_prefix}' has already been defined. Services cannot have ` +
`methods named get_<foo> and set_<foo> due to a hack in our js generation impl`);
}
this[without_prefix] = this[methodName]
return true
}
for (var [methodName, id, inType, outType] of methods) {
this[methodName] = gen_method(svc, id, inType, outType)
// HACK ALERT: the 'get_' prefix seems to be ignored by the fable binding. This was
// observed specifically in IAdminService.get_filtered_admin_data, and
// IAdminService.get_admin_data. Calls to those methods (from fsharp) failed in
// javascript due to undefined methods 'filtered_admin_data' and 'admin_data'
// respectively. Adding the methods with the prefix removed seems to fix the problem.
// TODO: replace this precarious fix (aka hack) with a stable solution.
const getter_prefix = "get_"
if (methodName.startsWith(getter_prefix)) {
this[methodName.substring(getter_prefix.length)] = this[methodName]
}
strip_prefix('get_') || strip_prefix('set_')
}
for (var [streamName,id,typeName] of streams) {
const fnName = "subscribe_" + streamName;