-
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
How deeply should we integrate with the ecosystem? #27
Comments
We could have dedicated utility crate that wraps common/verbose /// A convenience function for logging to the web browser's console. See also
/// the log! macro, which is more flexible.
pub fn log<S: ToString>(text: S) {
web_sys::console::log_1(&text.to_string().into());
}
/// Convenience function to avoid repeating expect logic.
pub fn window() -> web_sys::Window {
web_sys::window().expect("Can't find the global Window")
}
/// Convenience function to access the web_sys DOM document.
pub fn document() -> web_sys::Document {
window().document().expect("Can't find document")
}
/// Simplify getting the value of input elements; required due to the need to cast
/// from general nodes/elements to HTML__Elements.
pub fn input_value(target: &web_sys::EventTarget) -> String {
if let Some(input) = target.dyn_ref::<web_sys::HtmlInputElement>() {
return input.value();
}
if let Some(input) = target.dyn_ref::<web_sys::HtmlTextAreaElement>() {
return input.value();
}
if let Some(input) = target.dyn_ref::<web_sys::HtmlSelectElement>() {
return input.value();
}
"".into()
} These could be used either internally to Gloo modules/crates, or exposed in APIs. |
@David-OConnor I had thought of that, but that causes extra maintenance burden for everyone: crate authors and crate users. Putting the APIs as a submodule is much easier for everyone. I'm not against it, though I think there'd have to be a compelling argument to justify the extra complexity. If you meant that we should have a single utility crate, I don't think that's a good idea either: it will just end up as a jumbled mess of unrelated APIs. Keep in mind that even though right now the APIs are small and easy to manage, that won't be true forever: as Gloo becomes larger and more APIs are built, proper maintenance and API layering becomes very crucial. |
Thanks for starting this discussion, @Pauan, I think this is something we should definitely come to consensus on, and document in
+1 for being consistent.
What I care about more than exactly how it is done is exposing all layers of the onion as reusable pieces:
and then optionally, maybe, sometimes:
As far as how to expose the different layers of the onion, I think these are our choices:
I don't have any strong opinion here, but I'd note that the last has the best compile times for users (e.g. if they only used |
@fitzgen I generally agree with everything you said.
If we used Cargo
Indeed, I think the |
Correct. Again, at the cost of maintenance on our end (although probably less than a whole new crate, and neither is that much of a burden anyways...) |
One thing I'm curious about is how often we'd be able to distinguish a middle/high layer to abstract here (e.g. how many places it'd make sense to have a I suppose this also affects the compile time points you brought up @fitzgen because if the high level apis don't build on mid-level apis, then there's compile wins to be had for sure. If high builds on mid, though, I'm not sure crate separate will make much of a difference. |
@fitzgen Regarding
I think that
is wise. Identifying those needs and putting out a request-for-implementations to the community for each would likely produce sufficient variety for experimentation while retaining gloo contributor resources for focusing on the core layers. |
Instead of E.g. for timers we would have a |
It's not about internal details, it's about the API that is exposed to the user. From the user's perspective, a callback API is clearly lower level than a Future/Stream based API. I agree that there might be some gray areas where there isn't a clear division, but in the case of callbacks vs Future/Stream, it seems quite clear to me.
That's a good point. Personally, I think the high level APIs generally should be built on top of the mid level APIs, and if they aren't then that indicates the mid level APIs are designed poorly.
The downside is that it doesn't make it clear that Futures are the "blessed" way of doing things... but maybe that's actually not a downside? Maybe Gloo should be more unopinionated and just present both APIs fairly, and let the user decide. So I rather like that idea. |
I like the idea of just providing uniform representations of APIs across components, and having a common interface (ish) for both callback and futures-based primitives seems like a good idea. Sharing as many idioms across crates would be great (aka naming and API decision) |
Strong agree. |
I think we all seem to be in agreement here except maybe some bike shedding on exact naming of modules? Given that, would you like to make a PR that formalizes this stuff in |
PR created: #34 I think we should also discuss how deeply we should add in support for As I mentioned in some of the other issues, there are some APIs that are a perfect fit for Signals (e.g. DOM With the proposed system, that is easy to do: we just create a |
I've written 'FRP' style code (using RxJS) and it's phenomenal to develop and maintain. It does have a slight conceptual learning curve however in my experience it's paid off as well as that of Rust itself. |
Closing this issue for now, since I think we came up with a general plan for how to support different bits of the ecosystem in our crates. I think the question of whether to integrate with a specific crate/ecosystem can move into dedicated issues, for example the FRP/signals discussion should continue in #33 Thanks everyone! |
Right now web-sys provides very low-level access to the web APIs. My understanding is that Gloo is intended to create idiomatic high-level Rust APIs on top of those low-level APIs. However, there are different degrees of "high-level".
As an example, it's easy to wrap
setTimeout
andsetInterval
to make a nice convenient API that usesFnOnce
andFnMut
. But that's only slightly more high-level than using the APIs directly.On the other hand, we could wrap
setTimeout
andsetInterval
into aFuture
andStream
, which is definitely much higher level (and more idiomatic for Rust).So when we are faced with this choice between mid-level and high-level, what should we choose? I think we should have a consistent approach across the Gloo ecosystem.
I propose that we always expose the high-level APIs (
Future
,Stream
, etc.) and then have a submodule which exposes the mid-level APIs.That makes it clear that the high-level APIs are the idiomatic APIs that generally should be used, but still makes the mid-level APIs accessible for unusual circumstances.
To start the bikeshedding, I propose we consistently use the name
raw
for the mid-level submodule.The text was updated successfully, but these errors were encountered: