-
Notifications
You must be signed in to change notification settings - Fork 145
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: DOMContentLoaded future #10
Comments
This is another API which maps very well onto As a side note, when implementing this, you need to check |
I published https://github.com/yoshuawuyts/document-ready with the code we had from the all-hands. It still needs to be tested and probably polished a bit more, but happy to move it in here if people think it's useful! |
SummaryAdd layered APIs for document readiness. MotivationCode often doesn't want to start executing until the Web page's DOM has been fully constructed. It might want to grab a handle to a node that might not exist until the DOM is fully loaded. Additionally, one might dynamically add an Detailed ExplanationSimilar to the timers crate, this proposes a layered API where the first layer is the callback-y interface with Rust callbacks instead of
Drawbacks, Rationale, and AlternativesWe could potentially not take a document argument to simplify the API. However, besides allowing for working with We could potentially only expose the future type, and not the We could avoid the Unresolved Questions
|
Actually, that corresponds to the So it needs to be
I'm torn on that. There's good arguments for both. There's also the possibility of using the microtask event loop rather than the macrotask event loop (though that introduces another subtle inconsistency...) If somebody wants synchronous behavior, they can always manually check
I think Also, looking at your types, they seem to use Futures 0.1. I think that's a mistake: Futures are nearly stabilized, and so I think we should use Futures 0.3 instead. That also gives us access to async/await, which is huge. |
I think we should use 0.1 until 0.3 is published/stable. I'd like to avoid nightly completely. With
Good catch! |
How would you expose the callback-based readiness API? |
That's fair, though it wouldn't surprise me if Future becomes stable before Gloo starts to take off, so I'm hesitant to build a lot of things on top of Futures 0.1, simply because of the extra work involved...
As I proposed in this issue, I would put it into a pub fn on_ready<F>(document: &Document, f: F) -> Listener<'static, F> where F: FnOnce()
|
RAII-event deregistration issue posted here: #30 |
* Update to Rust 2021 and use JsError from gloo-utils * use new toolchain
* Initial commit * provide a better interface for errors, rename `RequestMethod` to `Method` * remove method for array buffer and blob in favor of as_raw * prepare for release * add CI, update readme * hide JsError in the docs * fix CI? * Install wasm-pack in CI * misc * websocket API Fixes: ranile/reqwasm#1 * add tests for websocket * update documentation, prepare for release * fix mistake in documentation * Rewrite WebSockets code (#4) * redo websockets * docs + tests * remove gloo-console * fix CI * Add getters for the underlying WebSocket fields * better API * better API part 2 electric boogaloo * deserialize Blob to Vec<u8> (#9) * Update to Rust 2021 and use JsError from gloo-utils (#10) * Update to Rust 2021 and use JsError from gloo-utils * use new toolchain * Add response.binary method to obtain response as Vec<u8> Fixes: ranile/reqwasm#7 * Remove `Clone` impl from WebSocket. When the WebSocket is used with frameworks, passed down as props, it might be `drop`ed automatically, which closes the WebSocket connection. Initially `Clone` was added so sender and receiver can be in different `spawn_local`s but it turns out that `StreamExt::split` solves that problem very well. See #13 for more information about the issue * Rustfmt + ignore editor config files * Fix onclose handling (#14) * feat: feature gate json, websocket and http; enable them by default (#16) * feat: feature gate json support * feat: feature gate weboscket api * ci: check websocket and json features seperately in CI, check no default features * feat: feature gate the http API * refactor: use futures-core and futures-sink instead of depending on whole of futures * ci: test http feature seperately in CI * fix: only compile error conversion funcs if either APIs are enabled * fix: add futures to dev-deps for tests, fix doc test * 0.3.0 * Fix outdated/missing docs * 0.3.1 * Change edition from 2021 to 2018 (#18) * Change edition from 2021 to 2018 * Fix missing import due to edition 2021 prelude * hopefully this will fix the issue (#19) * There's no message * Replace `async-broadcast` with `futures-channel::mpsc` (#21) We no longer need a multi-producer-multi-consumer channel. There's only one consumer as of ranile/reqwasm@445e9a5 * Release 0.4.0 * Fix message ordering not being preserved (#29) The websocket specification guarantees that messages are received in the same order they are sent. The implementation in this library can violate this guarantee because messages are parsed in a spawn_local block before being sent over the channel. When multiple messages are received before the next executor tick the scheduling order of the futures is unspecified. We fix this by performing all operations synchronously. The only part where async is needed is the conversion of Blob to ArrayBuffer which we obsolete by setting the websocket to always receive binary data as ArrayBuffer. * 0.4.1 * move files for gloo merge * remove licence files * gloo-specific patches * fix CI * re-export net from gloo Co-authored-by: Michael Hueschen <mhuesch@users.noreply.github.com> Co-authored-by: Stepan Henek <stepan+github@henek.name> Co-authored-by: Yusuf Bera Ertan <y.bera003.06@protonmail.com> Co-authored-by: Luke Chu <37006668+lukechu10@users.noreply.github.com> Co-authored-by: Valentin <vakevk+github@gmail.com>
Yosh and I started one at the 2019 Rust All Hands.
Give you a future for when the
DOMContentLoaded
event has fired.The text was updated successfully, but these errors were encountered: