绑定库:返回无类型对象 - 方法定义

binding library : returning untyped object - method definition

库的一部分我正在尝试绑定 returns 一个对象 -

Editor.prototype.getHandlers = function() {
  return {
    'shape.append': require('./draw/AppendShapeHandler'),
    'shape.create': require('./draw/CreateShapeHandler')
  };
};

我不知道如何指定 class 类型,因为返回的对象是匿名的:

class type editor = object
  method getHandlers : ? Js.t Js.opt Js.meth
end

有人可以在这里提出前进的方向吗?

谢谢

尼克

对于这种情况,可能是这样的:

class type editor = object
  method getHandlers : <shape_append : Js.js_string Js.t Js.meth> Js.t Js.meth
end

更多示例:

class type server = object
  method listen : int -> (unit -> unit) Js.callback -> unit Js.meth
  method close : (unit -> unit) Js.callback -> unit Js.meth
  method address :
            <address: Js.js_string Js.t Js.readonly_prop;
             family : Js.js_string Js.t Js.readonly_prop;
             port: Js.js_string Js.t Js.readonly_prop> Js.t Js.meth
end

这种以这种方式绑定的方法有效,但正如我在我的 OCaml nodejs 绑定中了解到的那样,最好在更高级别编写而不是执行这些绑定。 https://github.com/fxfactorial/ocaml-nodejs(查看早期的 git 历史,了解更多此类示例)