| #![allow(non_snake_case)] | |
| use dioxus::prelude::*; | |
| use std::cell::{Ref, RefCell, RefMut}; | |
| use std::collections::HashSet; | |
| use std::fmt::Display; | |
| use std::rc::Rc; | |
| #[derive(Clone)] | |
| struct SplitSubscriptions { | |
| a: LocalSubscription<i32>, |
| window.addEventListener('scroll', () => { | |
| let scrollTop = window.scrollY; | |
| let winHeight = window.document.documentElement.scrollHeight - window.document.documentElement.clientHeight; | |
| let new_scroll = Math.min(Math.max(scrollTop, 0) / Math.max(winHeight, 1), 1); | |
| document.body.style.setProperty('--scroll', new_scroll); | |
| }, false); |
| #![allow(non_snake_case)] | |
| use dioxus_signals::use_signal; | |
| use dioxus::prelude::*; | |
| use dioxus_fullstack::prelude::*; | |
| fn main() { | |
| LaunchBuilder::new(App).launch(); | |
| } | |
| fn App(cx: Scope) -> Element { |
| use kalosm::language::*; | |
| #[tokio::main] | |
| async fn main() { | |
| let local_source = LlamaSource::new( | |
| FileSource::Local("path/to/llama/model".into()), | |
| FileSource::Local("path/to/llama/tokenizer.json".into()), | |
| ) | |
| .with_group_query_attention( | |
| // 1 for llama, 8 for mistral |
| use criterion::*; | |
| criterion_group!(benches, leptos_ssr_bench, dioxus_ssr_bench); | |
| criterion_main!(benches); | |
| fn leptos_ssr_bench(c: &mut Criterion) { | |
| use leptos::*; | |
| let r = create_runtime(); | |
| c.bench_function("leptos ssr", |b| { | |
| b.iter(|| { |
Here is an overview of the state management system in dioxus. This doesn't cover all the internals, but it should serve as a pretty good reference:
Signal is like a fancy version of RefCell for UIs. Just like RefCell, it checks borrows at runtime. It has a bunch of helper methods to make it easier to use. Calling it like a function will clone the inner value. You can also call a few traits like AddAssign on it directly without writing to it manually.
// create a signal
let signal = use_signal(|| 0);| // candle-core = "0.8.4" | |
| use candle_core::Module; | |
| fn main() { | |
| let mut q_data = [[0f32; 256]; 256]; | |
| q_data[0][0] = 1.; | |
| q_data[0][1] = 2.; | |
| q_data[0][2] = 3.; | |
| q_data[1][0] = 3.; |
| use dioxus::prelude::*; | |
| use dioxus_primitives::select::{ | |
| Select, SelectGroup, SelectGroupLabel, SelectItemIndicator, SelectList, SelectOption, | |
| SelectTrigger, SelectValue, | |
| }; | |
| use strum::{EnumCount, IntoEnumIterator}; | |
| #[derive(Debug, Clone, Copy, PartialEq, strum::EnumCount, strum::EnumIter, strum::Display)] | |
| enum Fruit { | |
| Apple, |