Replies: 1 comment
-
I can't remember ways of forcing flat arrows with Fable. One way of working around your problem, is by using type MyType =
[<Emit(
"""
$0.all(function(error, rows) {
return $1(this, error, rows)
})
""")>]
abstract member all2: callback: (obj -> exn option -> ResizeArray<obj> -> unit) -> unit
let myType = unbox<MyType> null
myType.all2(fun sqlThis error rows ->
printfn "Hello"
) it will generates something like: myType.all(function(error, rows) {
return ((sqlThis, error, rows) => {
toConsole(printf("Hello"));
})(this, error, rows)
}); This is not the prettiest code but it should work 🤞 Another similar workaround to respect the original SQLite API is to create an helper to generate the flat function: type MyType =
// abstract member all: callback: (exn option -> ResizeArray<obj> -> unit) -> unit
abstract member all2: callback: (exn option -> ResizeArray<obj> -> unit) -> unit
module Adapter =
let all (callback : obj -> exn option -> ResizeArray<obj> -> unit) =
emitJsStatement (callback) """
function(error, rows) {
return $0(this, error, rows)
}
"""
let myType = unbox<MyType> null
myType.all2(Adapter.all (fun sqlThis error rows ->
printfn "Hello"
)) Personally, I would used the second option like that you can stay closer to the original API and the user opt-in using flat functions when needed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm binding to the
sqlite3
library and have a member that takes a callback:This callback gets a this of type
Statement
, which I'd like to be able to interact access viajsThis<Statement>
, but can't seem to get fable to generate anything other than an arrow function at the call site. Is it possible via an annotation or helper to force a function to not be an arrow?Beta Was this translation helpful? Give feedback.
All reactions