从F#Fable调用ES第三方脚本方法
我试图让Fable正确编译以下代码,但无法做到:从F#Fable调用ES第三方脚本方法,f#,fable-f#,F#,Fable F#,我试图让Fable正确编译以下代码,但无法做到: module AppView #r "../../../node_modules/fable-core/Fable.Core.dll" open Fable.Core open Fable.Import.Browser open Fable.Core.JsInterop [<Import("default", from="../../../js/3rd/riot.js")>] module riot_js = let mount:
module AppView
#r "../../../node_modules/fable-core/Fable.Core.dll"
open Fable.Core
open Fable.Import.Browser
open Fable.Core.JsInterop
[<Import("default", from="../../../js/3rd/riot.js")>]
module riot_js =
let mount:((string*obj)->array<obj>) = jsNative
type App
(
tagName:string
,state
,store
) =
member public x.AppTag =
(riot_js?mount ("app", state))
// does not compile: The value or constructor 'riot_js' is not defined.
// (riot_js.mount ("app", state))
// compiles wrongly to: riot_js.mount(["app", this.state]);
这将返回一个数组,但Fable不允许我以“正常”方式获取第一个元素:
在[
上显示红色,在表达式中出现错误意外符号“[”。应为标识符“(”或其他标记。
及
如果字段、构造函数或成员“项”未定义,则所有内容都显示红色,出现错误。
以下“作品”
并汇编为:
riot_js.mount("app", this.state)["0"];
这不是人们能得到的最佳结果。我会让这个问题搁置一段时间,并在《寓言》杂志开始2期之前悬赏一周左右。以下内容似乎编译到了正确的ES,不需要
?
,因此它将是强类型的
open Fable.Core.JsInterop
type Riotjs =
{
mount:(System.Func<string,obj,string []>)
}
let riot = (importAll<obj> "../js/3rd/riot.js") :?> Riotjs
let app = riot.mount.Invoke("app",(createObj []))
((riot_js 1)?mount ("app", state)).[0]
((riot_js 1)?mount ("app", state))?``0``
riot_js.mount("app", this.state)["0"];
open Fable.Core.JsInterop
type Riotjs =
{
mount:(System.Func<string,obj,string []>)
}
let riot = (importAll<obj> "../js/3rd/riot.js") :?> Riotjs
let app = riot.mount.Invoke("app",(createObj []))
export var app = riot.mount("app", {});