Replies: 1 comment
-
Have you had a look at I haven't used it before, least of all for websockets, but I think you will basically do 1) Set up your websocket, 2) Call create subscriber and call its |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I was wondering what the nicest way in Svelte 5 with runes of the following would be:
I have a
let myState = $state("some string")
which is synced via websocket. When a websocket message is received, the value should be updated. I also want to be able to bind it to an input field. Whenever the user types in the field or some other logic on the UI updates the value, it should be sent to the backend via websocket.Ideas I have considered:
Using
$effect
If I use a
$effect(() => sendViaWebsocket(myState)
, this triggers also after an incoming websocket message and sends the value back, although this is not neccessary :-(Using a wrapper class with a value copy
untested pseudocode in a
something.svelte.ts
file:this just feels complicated, and I always have to write
wrapper.state
instead ofstate
.Manually sending the websocket message
I could also just use a
onchange
for the input field, update the state there and also send the websocket message.However, then I loose the syntactical niceness of
bind:value
...I think syncing state via websocket is quite a common usecase. Therefore, does anyone have an idea on how to do this properly? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions