Skip to content

Instantly share code, notes, and snippets.

View ealmloff's full-sized avatar

Evan Almloff ealmloff

View GitHub Profile

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:

State

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);
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(|| {
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
@ealmloff
ealmloff / test.md
Last active December 28, 2023 00:09
Screenshot 2023-12-27 at 6 08 51 PM
#![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 {
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::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>,