I’m targeting the popular TanStack Query
Interesting you mention that, I vendor’d the rescriptbr ones because they had a few mistakes in them. I’d recently started working on binding them for v5 using some of the rescript v11 features:
type fetchStatus = | @as("fetching") Fetching | @as("paused") Paused | @as("idle") Idle
@tag("status")
type queryResult<'data> =
| @as("pending")
Pending({
data: unit,
dataUpdatedAt: int,
errorUpdateCount: int,
failureCount: int,
failureReason: Null.t<Error.t>,
fetchStatus: fetchStatus,
isFetched: bool,
isFetchedAfterMount: bool,
isPlaceholderData: bool,
isRefetchError: bool,
isStale: bool,
})
| @as("success")
Success({
data: 'data,
dataUpdatedAt: int,
error: unit,
errorUpdateCount: int,
failureReason: unit,
fetchStatus: fetchStatus,
isFetched: bool,
isFetchedAfterMount: bool,
isPlaceholderData: bool,
isRefetchError: bool,
isStale: bool,
})
| @as("error")
Error({
data: Nullable.t<'data>,
dataUpdatedAt: int,
error: Error.t,
errorUpdateCount: int,
failureCount: int,
failureReason: Null.t<Error.t>,
fetchStatus: fetchStatus,
isFetched: bool,
isFetchedAfterMount: bool,
isPlaceholderData: bool,
isRefetchError: bool,
isStale: bool,
})
Do you prefer reusing bindings or do you usually create them yourself?
Personally I try to contribute to any available bindings if at all feasible. The lack of OSS bindings is a huge barrier to entry to the Rescript community in my opinion, and learning to write the bindings is a skill unto itself when newcomers used to the JS ecosystem generally will not be as familiar with many of the patterns and concepts in FP languages. Trying to learn the type system, how to interpret the compiler, and also how to mentally translate what you are learning back into the javascript APIs, which often are at odds with how you would write Rescript code, is extraordinarily difficult for someone new.