feat: Add local attribute for Await (#1922)

This PR adds the ability to use `create_local_resource` instead of
`create_resource`. This will run the create resource locally on the
system and therefore its result type does not need to be `Seriaziable`.

Closes #1567
This commit is contained in:
Daniél Kerkmann 2023-10-22 00:34:02 +02:00 committed by GitHub
parent 12b0295906
commit 3e08486385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,8 @@ use crate::Suspense;
use leptos_dom::IntoView;
use leptos_macro::{component, view};
use leptos_reactive::{
create_blocking_resource, create_resource, store_value, Serializable,
create_blocking_resource, create_local_resource, create_resource,
store_value, Serializable,
};
#[component]
@ -44,6 +45,11 @@ pub fn Await<T, Fut, FF, VF, V>(
/// the HTML stream from returning anything before `future` has resolved.
#[prop(optional)]
blocking: bool,
/// If `true`, the component will use [`create_local_resource`], this will
/// always run on the local system and therefore its result type does not
/// need to be `Serializable`.
#[prop(optional)]
local: bool,
/// A function that takes a reference to the resolved data from the `future`
/// renders a view.
///
@ -101,6 +107,8 @@ where
{
let res = if blocking {
create_blocking_resource(|| (), move |_| future())
} else if local {
create_local_resource(|| (), move |_| future())
} else {
create_resource(|| (), move |_| future())
};