-
Notifications
You must be signed in to change notification settings - Fork 146
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
Utility crate for common web_sys features #72
Comments
I'm not sure about this one. The casting is ugly, yes, but that's handled by other things like #43 I think we should hold off on this until there's a clear use case which isn't handled by another higher-level crate.
I believe this is already handled by
They should probably use
I think the only case where it would fail is in WebWorkers (which run in a separate realm). It would also obviously fail in Node, but I think that's to be expected. Personally, I don't see much use for a utility crate if all it's doing is providing thin wrappers for unwrapping I think there would need to be stronger motivation than that (e.g. a dozen small APIs which don't really fit into any other crate). |
(To be clear, I'm not against the idea of a utility crate, and I agree that some things in web-sys could use some nicer wrappers, I just think this should incubate a bit first, it feels a bit too early to me) |
I feel like this is what all of Gloo is doing :-p My gut reaction is that we should try to identify specific cases and create utility crates for those cases, rather than making a catch-all miscellaneous crate. For example with
FWIW, we have the We could also re-export it in gloo potentially. A thing that I find myself doing for wasm projects is not relying on LTO to recognize that because logging is not enabled, it can remove the logging calls and their functions, and instead swapping out
Maybe it makes sense to centralize that dance in Gloo? |
Summary
I propose adding a crate that wraps common web_sys features with a cleaner API.
Examples:
Window
,Document
andHistory
in a way that handles failures automatically withexpect_throw
value
of input etc elementsconsole::log
andconsole::error
with a more flexible APIMotivation
The
web_sys
api can be verbose; high-level crates needn't each provide their own wrappers.Detailed Explanation
Some common features of
web_sys
are verbose when used directly. It's likely that manyGloo
crates will make use of them - let's settle on a general wrapping API higher-level crates can use. ExampleExamples:
Drawbacks, Rationale, and Alternatives
The original
web_sys
APIs aren't that clumsy - this might clutter upGloo
without providing much benefit. Perhaps we want to use pattern matching to handle failures ofweb_sys::Window
etc instead of usingexpect_throw
.It's easy to create a collection of helper functions that are intended to be general, but spread over a wide range of uses, some of which may not be common. It's possible that they may cover a smaller set of use-cases than intended. Thin wrappers in general can be seen as obfuscating the original, well-known API. Why build a new API that causes confusion with the one it wraps, when it's not much better?
Unresolved Questions
It's unclear what the scope of this should be. There are surely grey areas about what's appropriate here, and how cohesive/comprehensive it should be. What causes
web_sys::Window
etc to fail?I'm certainly biased by my own use-cases. Do y'all think these are, in-fact useful, general wrappers that would see use in many/most
Gloo
crates?I've only scratched the surface. What else should be added?
The text was updated successfully, but these errors were encountered: