-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider adding useful extension module #5
Comments
I think this type of thing should go in the module directly. I'd say that's an idiomatic binding. |
There will be other examples: type document
type element = {tag: string}
type htmlInputElement
@scope("document")
external querySelector: string => element = "querySelector"
external unsafeCast: 'i => 'o = "%identity"
let querySelectorInputElement = (selector: string): option<
htmlInputElement,
> => {
let i = querySelector(selector)
i.tag === "input" ? Some(unsafeCast(i)) : None
} This is not strictly a binding but does provide a safe API. |
Well, I think we definitely should ship "improved" APIs/helpers. Maybe others have differing opinions on this, but I think so at least. It'll increase the usefulness a lot for the lib. We need to figure out where to draw the line obviously. Here's an example of something similar that might fit here - helpers for working efficiently with |
While the aspiration of this project is to have bindings for anything available in the browser, it might be interesting consider having an additional auxiliary module.
Or to phrase it differently: some API methods are shit. Like https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement. You pass it any string and get an element back. Maybe you want to create something more specific and get a better type back like
document.createElement("input")
and getHTMLInputElement
back.So having something like:
The
input
string can't be misspelled and the return type is better.Perhaps each current API module can have an APIExt companion module?
Let me know what you thoughts.
The text was updated successfully, but these errors were encountered: