pub struct Driver { /* private fields */ }Expand description
Set of functions to communicate with 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 history_replace(&self, new_url: &str)
pub fn history_replace(&self, new_url: &str)
Replace current location
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 utc_now(&self) -> InstantType
pub fn utc_now(&self) -> InstantType
Gets current UTC timestamp
Sourcepub fn timezone_offset(&self) -> i32
pub fn timezone_offset(&self) -> i32
Gets browsers time zone offset in seconds
Compatible with chrono’s FixedOffset::east_opt method.
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.
Sourcepub fn dom_access(&self) -> DomAccess
pub fn dom_access(&self) -> DomAccess
Allows to access different objects in the browser (See js! macro for convenient use).
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
Sourcepub fn env(&self, name: impl Into<String>) -> Option<String>
pub fn env(&self, name: impl Into<String>) -> Option<String>
Get any env variable set upon starting vertigo server.
Sourcepub fn public_build_path(&self, path: impl Into<String>) -> String
pub fn public_build_path(&self, path: impl Into<String>) -> String
Get public path to build directory where the browser can access WASM and other build files.
Sourcepub fn route_to_public(&self, path: impl Into<String>) -> String
pub fn route_to_public(&self, path: impl Into<String>) -> String
Convert relative route to public path (with mount point attached)
Sourcepub fn route_from_public(&self, path: impl Into<String>) -> String
pub fn route_from_public(&self, path: impl Into<String>) -> String
Convert path in the url to relative route in the app.
Sourcepub fn plains(&self, callback: impl Fn(&str) -> Option<String> + 'static)
pub fn plains(&self, callback: impl Fn(&str) -> Option<String> + 'static)
Register handler that intercepts defined urls and generates plaintext responses during SSR.
Should 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
}
});Sourcepub fn set_status(&self, status: u16)
pub fn set_status(&self, status: u16)
Allow to set custom HTTP status code during SSR
use vertigo::get_driver;
get_driver().set_status(404)Sourcepub fn class_name_for(&self, css: &Css) -> String
pub fn class_name_for(&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.
Sourcepub fn register_bundle(&self, bundle: impl Into<String>)
pub fn register_bundle(&self, bundle: impl Into<String>)
Register css bundle
There shouldn’t be need to use it manually. It’s used by main! macro.