[英]How to expose F# module's public functions to Javascript via Fable?
[英]How to compile f# fable code to a multiple parameter javascript function
嗨,我正在嘗試為用 java 編寫的數據庫制作一些基本綁定,理想情況下我希望在 F# 中實際使用。 但是我對javascript相當陌生。 我設法使綁定與 1 個參數一起工作,但是由於在需要 3 個參數時嘗試調用具有 1 個參數的函數,因此多個參數使程序崩潰。
編碼:
type IRNCouchDBs =
abstract member Add : string*string*((string)->string)
[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative
添加在這種情況下是在 java 中,本質上是:
@ReactMethod
public void Add (String name, String type, Callback cb)
如果我像這樣調用 f# 代碼
let str (s : string) = s //just a test function
couchDB.Add ("name", "type", (str "test"))
然后發生錯誤,它抱怨我試圖將一個 1 參數函數傳遞給一個多參數函數。
任何如何解決這個問題的想法將不勝感激。
我想通了,回想起來相當明顯。
type IRNCouchDBs =
abstract member Add : Func<string, string, ((string*string->string)), unit>
[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative
let f' = (fun (x :string,y ) -> (x + y))
couchDB.Add.Invoke (fish.FishType,fish.Name, f')
使用 Func,並調用它,這似乎是這樣做的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.