tqwewe / leptos_server_signal

Leptos server signals synced through websockets
MIT License
58 stars 11 forks source link

Add support for client-writable signals #6

Open tqwewe opened 1 year ago

tqwewe commented 1 year ago

Currently, server signals are read only on the client, and cannot be updated other than by the server.

It would be nice to have writable signals from the client.

I assume this would involve a similar API to the server_fn macro, with a mpsc sender and receiver:

#[server_signal(Counter)]
pub async fn counter(count: i32, tx: Sender<i32>, mut rx: Receiver<i32>) -> Result<(), ServerFnError> {
    while let Some(new_count) = rx.receive().await? {
        println!("new count is {new_count}");
        tx.send(new_count + 1).await?;
    }

    Ok(())
}
Boscop commented 1 month ago

@tqwewe Yes, please! 🙏 It would be very useful to have a separate kind of signal that notifies the server of changes on the client side (from UI controls). Have you looked into this more? 🙂

tqwewe commented 1 month ago

@Boscop I haven't had a need for this in any of my projects yet, so haven't taken the time to look into it. If I do need it, I certainly will implement it, but sadly don't have the time to implement it currently. PRs are absolutely welcome for this if anyone wants to give it a shot.