PaginatedForProps

Struct PaginatedForProps 

Source
pub struct PaginatedForProps<T, L, Q, CF, V, M>
where T: Send + Sync + 'static, L: InternalLoader<M, Item = T, Query = Q> + 'static, L::Error: Send + Sync, Q: Send + Sync + 'static, CF: Fn((usize, Arc<T>)) -> V + Send + Clone + 'static, V: IntoView,
{ pub loader: L, pub query: Signal<Q>, pub state: Store<PaginationState>, pub item_count_per_page: Signal<usize>, pub overscan_page_count: usize, pub loading: Option<Loading>, pub load_error: Option<LoadError>, pub children: CF, pub _marker: PhantomData<(M, L)>, }
Expand description

Props for the PaginatedFor component.

Quite similar to Leptos’ <For> this displays a list of items.

But these items are loaded and cached on-demand using the provided loader.

§Example

pub struct Book {
    title: String,
    author: String,
}

let state = PaginationState::new_store();

view! {
    <ul>
        <PaginatedFor
            loader=BookLoader
            query=()
            state
            item_count_per_page=20
            let:idx_book
        >
            // Shown when the data has finished loading.
            <li class={if idx_book.0 % 2 == 0 { "even" } else { "odd" }}>
                <h3>{idx_book.1.title.clone()}</h3>
                <p>{idx_book.1.author.clone()}</p>
            </li>

            // Shown while the data is loading.
            <Loading slot>
                <li class="loading">Loading...</li>
            </Loading>
        </PaginatedFor>
    </ul>

    <div class="pagination-buttons">
        <PaginationPrev state attr:class="pagination-prev">
            "Previous"
        </PaginationPrev>
        <PaginationNext state attr:class="pagination-next">
            "Next"
        </PaginationNext>
    </div>
}

pub struct BookLoader;

impl ExactLoader for BookLoader {
    type Item = Book;
    type Query = ();
    type Error = ();

    async fn load_items(&self, range: Range<usize>, query: &Self::Query) -> Result<Vec<Self::Item>, Self::Error> {
        todo!()
    }

    async fn item_count(&self, _query: &Self::Query) -> Result<Option<usize>, Self::Error> {
        todo!()
    }
}

For more in-depth demonstration, please refer to the example pagination_rest_api.

§Required Props

  • loader: [L]
    • The loader to get the data on-demand.
  • query: impl Into<Signal<Q>>
    • The query to get the data on-demand.
  • state: [Store<PaginationState>]
    • The pagination state.

      Used to communicate between the pagination controls and this component.

  • item_count_per_page: impl Into<Signal<usize>>
    • How many items to display per page.
  • children: [CF]
    • The normal children are rendered when an item is loaded. This would be a normal <li> or <tr> element for example.

§Optional Props

  • overscan_page_count: usize
    • How many pages to load before and after the current page.

      A value of 1 means that the current page as well as the one before and after will be loaded. Defaults to 1.

  • loading: Loading
    • Slot that is rendered instead of children when the data is being loaded. This is recommended to be used to show a loading skeleton.
  • load_error: LoadError
    • Slot that is rendered instead of children when an error occurs.
  • _marker: PhantomData<(M, L)>

Fields§

§loader: L

The loader to get the data on-demand.

§query: Signal<Q>

The query to get the data on-demand.

§state: Store<PaginationState>

The pagination state.

Used to communicate between the pagination controls and this component.

§item_count_per_page: Signal<usize>

How many items to display per page.

§overscan_page_count: usize

How many pages to load before and after the current page.

A value of 1 means that the current page as well as the one before and after will be loaded. Defaults to 1.

§loading: Option<Loading>

Slot that is rendered instead of children when the data is being loaded. This is recommended to be used to show a loading skeleton.

§load_error: Option<LoadError>

Slot that is rendered instead of children when an error occurs.

§children: CF

The normal children are rendered when an item is loaded. This would be a normal <li> or <tr> element for example.

§_marker: PhantomData<(M, L)>

Implementations§

Source§

impl<T, L, Q, CF, V, M> PaginatedForProps<T, L, Q, CF, V, M>
where T: Send + Sync + 'static, L: InternalLoader<M, Item = T, Query = Q> + 'static, L::Error: Send + Sync, Q: Send + Sync + 'static, CF: Fn((usize, Arc<T>)) -> V + Send + Clone + 'static, V: IntoView,

Source

pub fn builder() -> PaginatedForPropsBuilder<T, L, Q, CF, V, M, ((), (), (), (), (), (), (), (), ())>

Create a builder for building PaginatedForProps. On the builder, call .loader(...), .query(...), .state(...), .item_count_per_page(...), .overscan_page_count(...)(optional), .loading(...)(optional), .load_error(...)(optional), .children(...), ._marker(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of PaginatedForProps.

Trait Implementations§

Source§

impl<T, L, Q, CF, V, M> Props for PaginatedForProps<T, L, Q, CF, V, M>
where T: Send + Sync + 'static, L: InternalLoader<M, Item = T, Query = Q> + 'static, L::Error: Send + Sync, Q: Send + Sync + 'static, CF: Fn((usize, Arc<T>)) -> V + Send + Clone + 'static, V: IntoView,

Source§

type Builder = PaginatedForPropsBuilder<T, L, Q, CF, V, M>

Source§

fn builder() -> Self::Builder

Auto Trait Implementations§

§

impl<T, L, Q, CF, V, M> Freeze for PaginatedForProps<T, L, Q, CF, V, M>
where L: Freeze, CF: Freeze,

§

impl<T, L, Q, CF, V, M> !RefUnwindSafe for PaginatedForProps<T, L, Q, CF, V, M>

§

impl<T, L, Q, CF, V, M> Send for PaginatedForProps<T, L, Q, CF, V, M>
where L: Send, M: Send,

§

impl<T, L, Q, CF, V, M> Sync for PaginatedForProps<T, L, Q, CF, V, M>
where L: Sync, CF: Sync, M: Sync,

§

impl<T, L, Q, CF, V, M> Unpin for PaginatedForProps<T, L, Q, CF, V, M>
where L: Unpin, CF: Unpin, M: Unpin,

§

impl<T, L, Q, CF, V, M> !UnwindSafe for PaginatedForProps<T, L, Q, CF, V, M>

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<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<El, T, Marker> IntoElementMaybeSignal<T, Marker> for El
where El: IntoElementMaybeSignalType<T, Marker>, Marker: ?Sized,

Source§

impl<T, Js> IntoElementMaybeSignalType<T, Element> for Js
where T: From<Js> + Clone,

Source§

impl<El, T, Marker> IntoElementsMaybeSignal<T, Marker> for El
where El: IntoElementsMaybeSignalType<T, Marker>, Marker: ?Sized,

Source§

impl<T, Js> IntoElementsMaybeSignalType<T, Element> for Js
where T: From<Js> + Clone,

Source§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,