Pauan / rust-dominator

Zero-cost ultra-high-performance declarative DOM library using FRP signals for Rust!
MIT License
998 stars 63 forks source link

Question: Tauri integration #46

Open AgarwalPragy opened 3 years ago

AgarwalPragy commented 3 years ago

Is there any non-trivial example that showcases how to share code b/w the backend and frontend when combining Dominator and Tauri?

Pauan commented 3 years ago

Well that depends a lot on your backend. Dominator doesn't handle state at all, it only handles displaying your state. So it's up to you how you want to manage your state.

If you're using WebSockets, then you would use the browser's WebSocket API to load the data from the server and then assign that data into Mutables.

If you're using HTTP, then you would just use standard APIs like fetch or XMLHttpRequest, just like how you would in JS.

In the case of Tauri specifically, there isn't really a "backend" or "frontend", it's all just frontend. You just import the @tauri-apps/api npm module and use it like how you would from JS. Since dominator compiles to Wasm, you can use all of the JS APIs just like how you normally would.

The Tauri team is working on creating wasm-bindgen bindings for @tauri-apps/api, so you should ask them about that.