I had encounter following code which implemented by TypeScript:
class A {
constructor(dispatch: (action) => void) {
this.props.dispatch = dispatch;
}
dispatch(action) {
this.props.dispatch.call(this, action)
}
}
function dispatch(action) {
// can use `this` and `action` here.
}
new A(dispatch)
And in ReScript, I binding it as:
// A.res
type t
@module('A') @new
let make = ((Action.t) => unit ) => t
When I try to create an instance of Module A
, the question is coming: how can I use the closures in dispatch
function:
let dispatch = action => {
// Only can use action.
}
let a = A.make(dispatch);
I tired to use following syntax, but it had been throw Error:
let a = A.make((action) => {
a.xxxxx // error
})