use gpui_kit::component::table::{TableDelegate, TableState};
use gpui_kit::{App, Context, Window};
pub trait LoadMoreDelegate: TableDelegate {
fn has_more(&self, app: &App) -> bool;
fn load_more_threshold(&self) -> usize {
10
}
fn load_more(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
}
pub trait TableDataLoader: TableDelegate {
fn load_data(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
}
pub trait TableLoader: TableDelegate {
const THRESHOLD: usize = 10;
fn load_more(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
}
#[cfg(test)]
mod tests {
use super::{LoadMoreDelegate, TableLoader};
use gpui_kit::component::table::{Column, TableDelegate, TableState};
use gpui_kit::{App, Context, IntoElement, Window, div};
struct Delegate;
impl TableDelegate for Delegate {
fn columns_count(&self, _cx: &App) -> usize {
0
}
fn rows_count(&self, _cx: &App) -> usize {
0
}
fn column(&self, _col_ix: usize, _cx: &App) -> Column {
unreachable!("the threshold contract does not inspect columns")
}
fn render_td(
&mut self,
_row_ix: usize,
_col_ix: usize,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
div()
}
}
impl LoadMoreDelegate for Delegate {
fn has_more(&self, _app: &App) -> bool {
true
}
fn load_more(&mut self, _window: &mut Window, _cx: &mut Context<TableState<Self>>) {}
}
impl TableLoader for Delegate {
fn load_more(&mut self, _window: &mut Window, _cx: &mut Context<TableState<Self>>) {}
}
#[test]
fn loading_traits_share_the_documented_default_threshold() {
assert_eq!(
<Delegate as LoadMoreDelegate>::load_more_threshold(&Delegate),
10
);
assert_eq!(<Delegate as TableLoader>::THRESHOLD, 10);
}
}