-
Notifications
You must be signed in to change notification settings - Fork 177
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
Two-way bindings between Webview and Rust Yew #135
Comments
I have not yet tried stdweb. I went with wasm_bindgen. It compiles in Rust, but errors out in JS at runtime. This happens even when just including wasm_bindgen and not invoking any functions (source code). I'm curious if there's a suggested path forward for this. |
|
@ante-dev @Boscop Here is an example of successfully executing I'm still trying to work out how to get messages going the other direction. One thing I tried was to inline stdweb |
@mbuscemi In your frontend (in your https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent Let me know how it goes :) |
@Boscop If I use |
It looks like |
@Boscop Here is where I'm at this morning. I've set up a
I found this article, but applying the
So, presuming this is how I'm supposed to set up the event listener, I'm unclear how to proceed. |
I've arrived at a working example of bi-directional communication. I explored using document and add_event_listener on the Rust side extensively. There doesn't seem to be an implementation of However, I was able to get this working by setting up a I'll check with the maintainer of stdweb if they have any interest in an implementation of That said, as per the topic of this ticket, two-way communication between Webview and Yew achieved. |
Nice! Btw:
self.event_listener = js! {
var set_file_callback = @{js_set_file_callback};
return event => set_file_callback(event.detail.contents);
}; And dropping would be like this: https://github.com/Boscop/yew-geolocation/blob/63dec0618393eda60becf8978a212c854f0ed5be/src/lib.rs#L133-L158 So you could just store a |
Good to know. I'm curious, as I had assumed that all My mind had already being going down a similar road as to your suggestion about the model. Mostly because (having already written large Elm apps), I'm thinking about how I want to organize the code when I have twenty or thirty or more of these communication points between Webview and Yew. I'll want a way to run through a vector or slice of them and initialize/destroy them all. By the way, I experimented with loading up a file containing double quotes, and it loaded up just fine under the current implementation. Perhaps Thanks for your help! |
Calling
It's because you're putting single quotes around the contents. But it would fail with single quotes in |
@Boscop How does this look for an implementation of cleaning up the callbacks? Also, you were right about the strings. The |
@mbuscemi Yeah it makes sense to factor the event stuff out.. js! {
var callback = @{js_callback};
var name = @{name};
var listener = event => callback(event.detail);
document.addEventListener(name, listener);
return {
callback: callback,
name: name,
listener: listener,
};
}; And then in And some minor things:
|
@Boscop Awesome suggestions!
|
Ah right, you had |
Putting this here for anyone who might find this in the future: https://github.com/mbuscemi/webview-yew-minimal |
I also took a stab at it (taking a lot of inspiration from the discussed approach): https://github.com/hobofan/yew_webview_bridge (also available on crates.io) A few notable points:
|
I'd also like this. Sadly I'm using seed and not yew so the premade solution won't work for me. And while I was prepared to build a custom local storage backend (since It'd be really great if the |
How can i call the invoke_handler from a Yew application? I want to communicate between Yew and Webview. I already tried adding javascript to Yew through stdweb and then calling
external.invoke("foo")
. But this doesn't work.The text was updated successfully, but these errors were encountered: