Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1751

How to bind to a js property that is a promise (not method)

$
0
0

Hi Agent Coop! Glad to see you’re interested in ReScript :slight_smile:

There are multiple ways to bind to JS types and modules.
The “traditional” way is to make the JS type an abstract type and use @send to bind to methods of this type and @get to bind to its properties (that’s the decorator you were missing in this case):

type viewTransition 

@get external viewTransitionFinished:  viewTransition => promise<unit> = "viewTransitionFinished"
@get external viewTransitionReady: viewTransition => promise<unit> = "viewTransitionReady"
@get external viewTransitionUpdateCallbackDone: viewTransition => promise<unit> = "viewTransitionUpdateCallbackDone"
@send external skipTransition: (viewTransition, unit) => unit = "skipTransition"

The other way is to make use of the uncurried mode and directly write methods and properties as fields of a record, as you’ve done:

type viewTransition = {
  viewTransitionFinished: promise<unit>,
  viewTransitionReady: promise<unit>,
  viewTransitionUpdateCallbackDone: promise<unit>,
  skipTransition: unit => unit,
}

This, though, has the drawback of only allowing one way to bind to a given property or method. It might be more suitable for simple types that have mostly imperative methods (methods that return unit).
It might be the case here.


Viewing all articles
Browse latest Browse all 1751

Trending Articles