Skip to main content

Module utils

Module utils 

Source
Expand description

A catch all for project-wide macros and general-purpose functions that are not directly related to Perspective.

Modules below crate::utils strive to be single-responsibility, but some reference other crate::utils modules when it helps reduce boiler-plate.

Structs§

DebounceMutex
An async Mutex type specialized for Perspective’s rendering, which debounces calls in addition to providing exclusivity. Calling debounce with a cancellable Future will resolve only after at least one complete evaluation of a call awaiting the lock.
PubSub
A pub/sub struct which allows many listeners to subscribe to many publishers, without leaking callbacks as listeners are dropped.
Subscriber
Like a PubSub without PubSub::emit; the reciprocal of PubSub::callback. Subscriber does not keep the parent PubSub alive.
Subscription
Manages the lifetime of a listener registered to a PubSub<T> by deregistering the associated listener when dropped.
WeakScope
A mutable reference for capturing the Scope props arguments, a useful function for tests.

Enums§

DragEffect
DragTarget

Traits§

AddListener
An extension trait for AddListener::add_listener, which we want to take a variety of function-like arguments for readability.
AsBlob
An extension method for converting various js_sys and web_sys types to web_sys::Blob.
CaretPosition
Utilities for caret position. DOM elements have different APIs for this but Deref makes them fall through, so it is important that this method be called on the correct struct type!
CustomElementMetadata
A trait which allows the define_web_component method to create a Custom Element (which must by definition inherit from HTMLElement) from a [wasm_bindgen] annotated Rust struct (for which this trait is implemented).
u32Ext
Trait for the u32::to_formatted_string method.

Functions§

await_dom_loaded
An async which awaits the browser’s load event, which is automatically bypassed if document.readyState indicates this has already occurred.
await_queue_microtask
An async version of queueMicrotask(), curiously absent from web_sys.
define_web_component
Register the Custom Element globally.
download
Given a blob, invoke the Browser’s download popup.
posix_to_utc_str
Convert POSIX timestamp to a formatted string.
request_animation_frame
An async version of requestAnimationFrame(), which resolves on the next animation frame.
set_timeout
An async version of set_timeout, which resolves in timeout milliseconds
str_to_utc_posix
Convert a String datetime representation to a POSIX timestamp.
use_async_callback
Just like use_callback, except convenient for an async result body.