mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-14 00:27:12 +00:00
update js-framework-benchmark example
This commit is contained in:
parent
131c83e28e
commit
a03d74494d
4 changed files with 19 additions and 28 deletions
|
@ -8,9 +8,7 @@ codegen-units = 1
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
leptos = { path = "../../leptos", features = ["csr","template_macro"] }
|
leptos = { path = "../../leptos", features = ["csr", "nightly"] }
|
||||||
console_log = "1"
|
|
||||||
log = "0.4"
|
|
||||||
# used in rand, but we need to enable js feature
|
# used in rand, but we need to enable js feature
|
||||||
getrandom = { version = "0.2.7", features = ["js"] }
|
getrandom = { version = "0.2.7", features = ["js"] }
|
||||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
rand = { version = "0.8.5", features = ["small_rng"] }
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "stable" # test change
|
channel = "nightly"
|
||||||
|
|
|
@ -39,10 +39,10 @@ static NOUNS: &[&str] = &[
|
||||||
"sandwich", "burger", "pizza", "mouse", "keyboard",
|
"sandwich", "burger", "pizza", "mouse", "keyboard",
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
struct RowData {
|
struct RowData {
|
||||||
id: usize,
|
id: usize,
|
||||||
label: (ReadSignal<String>, WriteSignal<String>),
|
label: ArcRwSignal<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID_COUNTER: AtomicUsize = AtomicUsize::new(1);
|
static ID_COUNTER: AtomicUsize = AtomicUsize::new(1);
|
||||||
|
@ -67,7 +67,7 @@ fn build_data(count: usize) -> Vec<RowData> {
|
||||||
|
|
||||||
data.push(RowData {
|
data.push(RowData {
|
||||||
id: ID_COUNTER.load(Ordering::Relaxed),
|
id: ID_COUNTER.load(Ordering::Relaxed),
|
||||||
label: create_signal(label),
|
label: ArcRwSignal::new(label),
|
||||||
});
|
});
|
||||||
|
|
||||||
ID_COUNTER
|
ID_COUNTER
|
||||||
|
@ -96,8 +96,8 @@ fn Button(
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
let (data, set_data) = create_signal(Vec::<RowData>::new());
|
let (data, set_data) = signal(Vec::<RowData>::new());
|
||||||
let (selected, set_selected) = create_signal(None::<usize>);
|
let (selected, set_selected) = signal(None::<usize>);
|
||||||
|
|
||||||
let remove = move |id: usize| {
|
let remove = move |id: usize| {
|
||||||
set_data.update(move |data| data.retain(|row| row.id != id));
|
set_data.update(move |data| data.retain(|row| row.id != id));
|
||||||
|
@ -120,7 +120,7 @@ pub fn App() -> impl IntoView {
|
||||||
let update = move |_| {
|
let update = move |_| {
|
||||||
data.with(|data| {
|
data.with(|data| {
|
||||||
for row in data.iter().step_by(10) {
|
for row in data.iter().step_by(10) {
|
||||||
row.label.1.update(|n| n.push_str(" !!!"));
|
row.label.update(|n| n.push_str(" !!!"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -138,7 +138,7 @@ pub fn App() -> impl IntoView {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_selected = create_selector(move || selected.get());
|
let is_selected = Selector::new(move || selected.get());
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -162,30 +162,22 @@ pub fn App() -> impl IntoView {
|
||||||
<table class="table table-hover table-striped test-data">
|
<table class="table table-hover table-striped test-data">
|
||||||
<tbody>
|
<tbody>
|
||||||
<For
|
<For
|
||||||
each=move || data.get()
|
each={move || data.get()}
|
||||||
key=|row| row.id
|
key={|row| row.id}
|
||||||
children=move |row: RowData| {
|
children=move |row: RowData| {
|
||||||
let row_id = row.id;
|
let row_id = row.id;
|
||||||
let (label, _) = row.label;
|
let label = row.label;
|
||||||
on_cleanup({
|
|
||||||
let is_selected = is_selected.clone();
|
let is_selected = is_selected.clone();
|
||||||
move || {
|
ViewTemplate::new(view! {
|
||||||
label.dispose();
|
|
||||||
is_selected.remove(&Some(row_id));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let is_selected = is_selected.clone();
|
|
||||||
template! {
|
|
||||||
<tr class:danger={move || is_selected.selected(Some(row_id))}>
|
<tr class:danger={move || is_selected.selected(Some(row_id))}>
|
||||||
<td class="col-md-1">{row_id.to_string()}</td>
|
<td class="col-md-1">{row_id.to_string()}</td>
|
||||||
<td class="col-md-4"><a on:click=move |_| set_selected.set(Some(row_id))>{label}</a></td>
|
<td class="col-md-4"><a on:click=move |_| set_selected.set(Some(row_id))>{label}</a></td>
|
||||||
<td class="col-md-1"><a on:click=move |_| remove(row_id)><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
|
<td class="col-md-1"><a on:click=move |_| remove(row_id)><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
|
||||||
<td class="col-md-6"/>
|
<td class="col-md-6"/>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
|
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use js_framework_benchmark_leptos::App;
|
use js_framework_benchmark_leptos::App;
|
||||||
use leptos::{wasm_bindgen::JsCast, *};
|
use leptos::{
|
||||||
|
leptos_dom::helpers::document, mount::mount_to, wasm_bindgen::JsCast,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
_ = console_log::init_with_level(log::Level::Debug);
|
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
let root = document().query_selector("#main").unwrap().unwrap();
|
let root = document().query_selector("#main").unwrap().unwrap();
|
||||||
mount_to(root.unchecked_into(), || view! { <App/> });
|
let handle = mount_to(root.unchecked_into(), App);
|
||||||
|
handle.forget();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue