pub struct Driver { /* private fields */ }
Expand description
Main connection to vertigo facilities - dependencies and rendering client (the browser).
Implementations§
source§impl Driver
impl Driver
Gets a cookie by name
Gets a JsJson cookie by name
Sets a cookie under provided name
Sets a cookie under provided name
sourcepub fn history_back(&self)
pub fn history_back(&self)
Go back in client’s (browser’s) history
sourcepub fn set_interval(&self, time: u32, func: impl Fn() + 'static) -> DropResource
pub fn set_interval(&self, time: u32, func: impl Fn() + 'static) -> DropResource
Make func
fire every time
seconds.
sourcepub fn request_get(&self, url: impl Into<String>) -> RequestBuilder
pub fn request_get(&self, url: impl Into<String>) -> RequestBuilder
Create new RequestBuilder for GETs (more complex version of fetch)
sourcepub fn request_post(&self, url: impl Into<String>) -> RequestBuilder
pub fn request_post(&self, url: impl Into<String>) -> RequestBuilder
Create new RequestBuilder for POSTs (more complex version of fetch)
pub fn sleep(&self, time: u32) -> FutureBox<()> ⓘ
pub fn get_random(&self, min: u32, max: u32) -> u32
pub fn get_random_from<K: Clone>(&self, list: &[K]) -> Option<K>
sourcepub fn websocket<F: Fn(WebsocketMessage) + 'static>(
&self,
host: impl Into<String>,
callback: F
) -> DropResource
pub fn websocket<F: Fn(WebsocketMessage) + 'static>( &self, host: impl Into<String>, callback: F ) -> DropResource
Initiate a websocket connection. Provided callback should handle a single WebsocketMessage.
sourcepub fn spawn(&self, future: impl Future<Output = ()> + 'static)
pub fn spawn(&self, future: impl Future<Output = ()> + 'static)
Spawn a future - thus allowing to fire async functions in, for example, event handler. Handy when fetching resources from internet.
sourcepub fn transaction<R, F: FnOnce(&Context) -> R>(&self, func: F) -> R
pub fn transaction<R, F: FnOnce(&Context) -> R>(&self, func: F) -> R
Fire provided function in a way that all changes in dependency graph made by this function will trigger only one run of updates, just like the changes were done all at once.
pub fn dom_access(&self) -> DomAccess
sourcepub fn on_after_transaction(
&self,
callback: impl Fn() + 'static
) -> DropResource
pub fn on_after_transaction( &self, callback: impl Fn() + 'static ) -> DropResource
Function added for diagnostic purposes. It allows you to check whether a block with a transaction is missing somewhere.
sourcepub fn is_browser(&self) -> bool
pub fn is_browser(&self) -> bool
Return true if the code is executed client-side (in the browser).
use vertigo::{dom, get_driver};
let component = if get_driver().is_browser() {
dom! { <div>"My dynamic component"</div> }
} else {
dom! { <div>"Loading... (if not loaded check if JavaScript is enabled)"</div> }
};
pub fn is_server(&self) -> bool
pub fn env(&self, name: impl Into<String>) -> Option<String>
sourcepub fn plains(&mut self, callback: impl Fn(&str) -> Option<String> + 'static)
pub fn plains(&mut self, callback: impl Fn(&str) -> Option<String> + 'static)
Register handler that intercepts defined urls and generates plaintext responses during SSR.
Return None in the handler if regular HTML should be generated by the App.
use vertigo::get_driver;
get_driver().plains(|url| {
if url == "/robots.txt" {
Some("User-Agent: *\nDisallow: /search".to_string())
} else {
None
}
});
pub fn try_get_plain(&self)
sourcepub fn class_name_for(&mut self, css: &Css) -> String
pub fn class_name_for(&mut self, css: &Css) -> String
Adds this CSS to manager producing a class name, which is returned
There shouldn’t be need to use it manually. It’s used by css!
macro.