Driver

Struct Driver 

Source
pub struct Driver { /* private fields */ }
Expand description

Set of functions to communicate with the browser.

Implementations§

Source§

impl Driver

Source

pub fn cookie_get(&self, cname: &str) -> String

Gets a cookie by name

Source

pub fn cookie_get_json(&self, cname: &str) -> JsJson

Gets a JsJson cookie by name

Source

pub fn cookie_set(&self, cname: &str, cvalue: &str, expires_in: u64)

Sets a cookie under provided name

Source

pub fn cookie_set_json(&self, cname: &str, cvalue: JsJson, expires_in: u64)

Sets a cookie under provided name

Source

pub fn history_back(&self)

Go back in client’s (browser’s) history

Source

pub fn history_replace(&self, new_url: &str)

Replace current location

Source

pub fn set_interval(&self, time: u32, func: impl Fn() + 'static) -> DropResource

Make func fire every time seconds.

Source

pub fn now(&self) -> Instant

Gets current value of monotonic clock.

Source

pub fn utc_now(&self) -> InstantType

Gets current UTC timestamp

Source

pub fn timezone_offset(&self) -> i32

Gets browsers time zone offset in seconds

Compatible with chrono’s FixedOffset::east_opt method.

Source

pub fn request_get(&self, url: impl Into<String>) -> RequestBuilder

Create new RequestBuilder for GETs (more complex version of fetch)

Source

pub fn request_post(&self, url: impl Into<String>) -> RequestBuilder

Create new RequestBuilder for POSTs (more complex version of fetch)

Source

pub fn sleep(&self, time: u32) -> FutureBox<()>

Source

pub fn get_random(&self, min: u32, max: u32) -> u32

Source

pub fn get_random_from<K: Clone>(&self, list: &[K]) -> Option<K>

Source

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.

Source

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.

Source

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.

Source

pub fn dom_access(&self) -> DomAccess

Allows to access different objects in the browser (See js! macro for convenient use).

Source

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.

Source

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> }
};
Source

pub fn is_server(&self) -> bool

Source

pub fn env(&self, name: impl Into<String>) -> Option<String>

Get any env variable set upon starting vertigo server.

Source

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.

Source

pub fn route_to_public(&self, path: impl Into<String>) -> String

Convert relative route to public path (with mount point attached)

Source

pub fn route_from_public(&self, path: impl Into<String>) -> String

Convert path in the url to relative route in the app.

Source

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
   }
});
Source

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)
Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Driver

§

impl !RefUnwindSafe for Driver

§

impl !Send for Driver

§

impl !Sync for Driver

§

impl Unpin for Driver

§

impl !UnwindSafe for Driver

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.