From febfbb90b0034dc002e47cc520faca1fd383fd20 Mon Sep 17 00:00:00 2001 From: xeovalyte Date: Mon, 19 Feb 2024 10:53:13 +0100 Subject: [PATCH] Added documentation --- application/src/lib.rs | 2 +- application/src/util/surrealdb.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/src/lib.rs b/application/src/lib.rs index 8e501a2..8f74d53 100644 --- a/application/src/lib.rs +++ b/application/src/lib.rs @@ -63,7 +63,7 @@ pub fn App() -> impl IntoView { diff --git a/application/src/util/surrealdb.rs b/application/src/util/surrealdb.rs index c778440..9b09337 100644 --- a/application/src/util/surrealdb.rs +++ b/application/src/util/surrealdb.rs @@ -73,11 +73,13 @@ impl SurrealContext { } } + /// Send a string to surrealDB #[inline(always)] pub fn send(&self, message: &str) { (self.send)(message) } + /// sigin SurrealDB pub fn signin(&self, pass: String) { log::debug!("Signing into surrealdb"); @@ -95,6 +97,7 @@ impl SurrealContext { } pub fn init_surrealdb() { + // Initialize a connection to surrealDB let UseWebsocketReturn { ready_state, message, @@ -102,9 +105,11 @@ pub fn init_surrealdb() { .. } = use_websocket("ws://localhost:80/rpc"); + // Create reactive signals for the websocket connection to surrealDB let (participants, _set_participants) = create_signal::>(vec![]); let (authenticated, set_authenticated) = create_signal::(false); + // Bind the websocket connection to a context let websocket = SurrealContext::new( message, Rc::new(send.clone()), @@ -116,6 +121,7 @@ pub fn init_surrealdb() { provide_context(websocket); provide_context(ParticipantsContext(participants)); + // Watch for a message recieved from the surrealDB connection create_effect(move |prev_value| { let msg = message.get();