2016-07-29 6 views
0

joocを使用してd3-forceのサブセットをラップするのに問題があります。ライブラリはオブジェクトのプロパティを使用せず、代わりに融合されたgetter-setter関数を実装します。融合getter-setter関数をラップする

simulation.force("x", d3.forceX()) // setter 
simulation.force("x")    // getter 

OCamlで同じ種類の多型をエミュレートする方法を知りたいと思います。ここで私は現在、

module Force = struct 
    class type force = object 
    (* not important *) 
    end 

    let x(): force Js.t = Js.Unsafe.meth_call __d3 "forceX" [||] 

    class type simulation = object 
    method force : string -> #force Js.t -> unit Js.meth 
    end 

    let simulation nodes: simulation Js.t = 
    Js.Unsafe.(meth_call __d3 "forceSimulation" [|inject nodes|]) 
end 

を持っているものだと、ここで私は何の文字列はocamlのものと互換性がありませんJavaScriptの

let s = Force.simulation nodes in begin 
    s##force "x" (Force.x()) 
    s##force "x" (* wishful thinking *) 
end 

答えて

1
class type simulation = object 
    method force_set : Js.js_string Js.t -> #force Js.t -> unit Js.meth 
    method force : Js.js_string Js.t -> #force Js.t Js.meth 
end 
+0

ありがとう、本当にありがとう! –