【发布时间】:2017-08-19 07:07:28
【问题描述】:
我正在尝试让 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:((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]);
尝试riot_js?mount 会神奇地导致riot_js 不再存在,而尝试riot_js.mount 会编译成riot_js.mount(["app", this.state]);。
Mount 不接受一个参数,而是接受 2 个参数,但它要么不会转译,要么转译错误。
现在我有一个看起来最奇怪的解决方案:
[<Emit("riot_js")>]
let riot_js (x: int): obj = jsNative
...
((riot_js 1)?mount ("app", state))
这会返回一个数组,但 Fable 再次不允许我以“正常”方式获取第一个元素:
((riot_js 1)?mount ("app", state))?[0]
在[ 上给我红色,错误Unexpected symbol '[' in expression. Expected identifier, '(' or other token.
和
((riot_js 1)?mount ("app", state)).[0]
出现错误The field, constructor or member 'Item' is not defined.的所有内容都显示为红色
以下“作品”
((riot_js 1)?mount ("app", state))?``0``
并编译为:
riot_js.mount("app", this.state)["0"];
不是别人能得到的最好结果。在打开 Fable 的 2 个问题之前,我将让这个问题搁置一段时间,并设置赏金一周左右的时间。
【问题讨论】: