-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
HtmlTextAreaElement and mogwai 0.5.0 #89
Comments
So far, I've managed to acquire a HtmlTextAreaElement from post:build: <textarea post:build=move |dom: &mut Dom| {
match dom.inner_read() {
Either::Left(rwguard) => {
let area = rwguard.clone().dyn_into::<HtmlTextAreaElement>();
loop {
rxv.clone() // ??
}
}
Either::Right(ssr) = {} } }> But I can't find a way to poll a stream from there. And that's a read-write guard that I don't think that one should be holding on to indefinitely in a loop anyway. |
The way that I've been dealing with this is to use the fn view(tx: Sender<Dom>) -> ViewBuilder<Dom> {
builder! {
<textarea post:build=move |dom: &mut Dom| {
tx.try_send(dom.clone()).unwrap();
}></textarea>
}
}
async fn logic(mut rx: Receiver<Dom>) {
let text_area_dom = rx.next().await.unwrap();
{
if let Some(text_area) = text_area_dom.clone_as::<HtmlTextAreaElement>() {
// ... do `web_sys` stuff with text_area
}
}
loop { // ... loop as normal }
} There's an entry in the mogwai cookbook about capturing parts of the view that may help. There are also a few examples of this in the examples dir. Let me know what you think :) |
Was using a ::broadcast channel to send things to the logic, and a ::mpmc to send things to the view, after the examples in the cookbook. Your example uses tx.try_send() from a ::mpmc channel. So in the logic 183 | let mut sources = mogwai::futures::stream::select_all(vec![rx_broadcast.boxed(), rx_mpmc.boxed()]);
| ^^^^^ `*mut u8` cannot be shared between threads safely So I'm trying to refactor the component architecture I'm trying to establish, to only use ::mpmc to send things to the logic. It's very tricky to figure out an architecture that is consistent to focus on the business logic. |
I don't think it makes sense for everything to be asynchronous. The complexities involved in performing basic logic will have one fiddling with channels for days, and we haven't even begun on the business logic of the application. Asynchronous programming should be a tool that you use to achieve something, instead of for interacting with the API which serves no purpose from what I can tell, but to prevent one from programming. Given the asynchronous nature of 0.5.0 it looks like we should only use ::broadcast channels exclusively, so that we don't run into issues later. But now I can't send a mogwai::prelude::Dom through a ::broadcast channel in WASM because its wasm_bindgen::JsValue isn't std::marker::Send. I'm going back to refactoring again using ::mpmc channels, but the logic already has a loop reading ::broadcast messages, and blocking on .await. Where do you handle the ::mpmc messages? let mut sources = mogwai::futures::stream::select_all(vec![rxl.boxed()]);
loop {
match sources.next().await { }
} |
Hopefully I can address all your concerns.
This can be true. Even if you're used to working with the various channels it's easy to get confused. This is something I'll be working on in the future. It would be easier if channel implementations'
I agree, though I think the logic loops should be asynchronous because you often have to
This is mostly correct. If you don't have a specific reason not to use a
You are correct that The reason to use Thanks for exposing the confusion in channels. I'll have to do something to fix that. I'll probably drop |
And with regards to send_async and safety, all of my code that interacts with javascript is kept in a separate mod, and that still requires: wasm_bindgen_futures::spawn_local(async move {
}); Because they use JsValue objects from Javascript that are not "Send", so you cannot JsFuture::from(promise_with_jsvalue_objects).await from mogwai with_logic() loop. So again all of my code is async everywhere for seemingly no purpose, but all interaction with javascript requires wasm_bindgen_futures::spawm_local. |
I see the confusion. Currently each time you call It does make sense that you would think it appends the logic though, and the implementation could do that, if desired. I suppose that would be preferable to using types to ensure that this confusion never happens (which would mean I understand your frustration with the new changes. Trying to anticipate some that frustration I included the IsElmComponent trait, which works almost exactly the same as Given some more time I'd like to rewrite your example to help you out, but I won't be able to until tomorrow morning (NZ time). |
Thank you, closing issue. I understand how to use it now, deleted my whining posts, my bad. Great framework! |
Thanks for the issue - it has illuminated some of the areas of mogwai that I haven't thought enough about. 🙇 |
Hi, is it possible to send content to a <textarea> element somehow?
The <textarea> element requires a call to HtmlTextAreaElement::value() attribute but I haven't found a way to do this from the view or logic code.
I can't find a way to cast an element inside a builder! {} ViewBuilder to HtmlTextAreaElement to call the value() method, and I can't seem to send messages to it in any way that calls the value() method.
Note this is not the <textarea value= /> attribute, which you can send messages to fine, but it's a method in javascript on the element.
Some help with how to do this would be highly appreciated!
Thank you!
The text was updated successfully, but these errors were encountered: