Skip to content

struct

Resource

pub struct Resource {
    pub data: Signal<Value>,
    pub loading: Signal<bool>,
    pub error: Signal<Option<String>>,
}

Loading state for templates: bind it with [Resource::bind] and fill it with weft::web::load (or [Resource::set]).

let posts = Resource::new();
weft::web::load(&posts, async move { wp.posts(&query).send().await });
posts.bind(Scope::new(), "posts")
// template: if posts_loading { Skeleton } else if posts_error { Alert … } else { for p in posts { … } }

Fields

data

pub data: Signal<Value>

The data, once loaded (null before).

loading

pub loading: Signal<bool>

Whether a load is in flight.

error

pub error: Signal<Option<String>>

Why the last load failed, if it did.

Methods

new

pub fn new() -> Resource

Starts out loading, with no data.

start

pub fn start(&self)

Mark it loading again (keeps the old data while it refreshes).

set

pub fn set<E: Display>(&self, result: Result<Value, E>)

Store a result.

bind

pub fn bind(&self, scope: Scope, name: &str) -> Scope

name (the data), name_loading and name_error (text or null).

Trait implementations