Attribute Macro bounce::future_notion

source ·
#[future_notion]
Expand description

A future-based notion that notifies states when it begins and finishes.

A future notion accepts a signle argument as input and returns an output.

It can optionally accept a states parameter which has a type of BounceStates that can be used to access bounce states when being run.

The async function must have a signature of either Fn(&I) -> impl Future<Output = O> or Fn(&BounceState, &I) -> impl Future<Output = O>.

Both Input and Output must live 'static.

Example

use std::rc::Rc;
use bounce::prelude::*;
use yew::prelude::*;

struct User {
    id: u64,
    name: String,
}

#[future_notion(FetchData)]
async fn fetch_user(id: &u64) -> User {
    // fetch user

    User { id: *id, name: "John Smith".into() }
}

See: use_future_notion_runner