ReasonML Journey Part III: Generics, Promises, and ExtendableEvent.waitUntil()bucklescript promise reasonml
ExtendableEvent in ReasonML. In this post I will show how to extend the subtype of
ExtendableEvent's waitUntil method, which takes a generic
Promise as a parameter.
[@bs.send] external getElementById: (document, string) => Dom.element
In this example,
[@bs.send] external tells BuckleScript to call out
trusting that there is such a function as the string
rest of the statement provides the types we will use to interact with it. We
need to adapt this to take a type parameter for our promise.
[@bs.send] external waitUntil: (extendableEvent, Js.Promise.t('a)) => unit
"waitUntil", which takes our
extendableEvent as a first "parameter" (in this context) and a strongly typed
unit, which, in functional languages, is like
This doesn't quite do what we need though--we need this method of
ExtendableEvent to be heritable. We can do this by using our supertype.
external waitUntil: (extendableEvent_like('subtype), Js.Promise.t('a)) => unit
waitUntil to accept any subtype of
And we're done for the day. In the next post, I'll work on the npm side of things so that we can use our new type elsewhere.
I write to learn, so I welcome your constructive criticism. Report issues on GitLab.