Loading repository data…
Loading repository data…
brklntmhwk / repository
A playground for learning front/backend Rust web frameworks: Leptos and Axum respectively, plus, SeaORM(Postgres) for database relations.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This repo walks you through a bunch of both client-side and server-side features Leptos provides, such as signals, resources, and server functions.
These are some notes of what I've learnt through tinkering with this app.
cargo-leptos helps coordinate the build process that requires two separate binaries: one compiled to native code and running the server, and the other compiled to WASM and running in the browser.
leptos-app, they are backend and frontend, respectively.cargo leptos watchleptos_axum and leptos_actix, such method as leptos_routes(), or leptos_routes_with_handler() takes route list, decides how to handle it, and generates a list of all possible routes your app can handle<App/>) with the URL being requested and other data such as the HTTP headerscreate_signal is similar to useState in React, and almost equivalent to createSignal in SolidJScreate_effect is almost equivalent to useEffect in React, but there's a difference;
use_last is true, the effect will rerun whenever first, last, or use_lastchanges in this casefirst be the tracking targetlet (first, set_first) = create_signal(String::new());
let (last, set_last) = create_signal(String::new());
let (use_last, set_use_last) = create_signal(true);
create_effect(move |_| {
log(
if use_last.get() {
format!("{} {}", first.get(), last.get())
} else {
first.get()
},
)
});
create_resource allows you to integrate async into the sync reactive system
Future into a signal that returns Some(T) if it's resolved, and None if it's still pending, rather than waiting for its data to be loaded with .asyncuseSWR or useSWRInfinite in swr, a React hooks library, it takes a source signal as its first arg, and a fetcher as its second onelet (count, set_count) = create_signal(0);
let async_data = create_resource(
count, // a source signal
|value| async move {
logging::log!("loading data from API");
load_data(value).await
}, // a fetcher (every time `count` changes, this will run)
);
let once = create_resource(|| (), |_| async move { load_data().await });
create_resource, create_action is more suitable for a situation where an async function needs to run in response to a user's action such as clicking a button
create_action for add_todo, create_resource for list_todoscreate_resource, create_local_resource handles local resources that don't load on the server but in the browser
Future that a fetcher will generate runs only on the local system, its data type doesn't need to be serializable<Suspense> and <Transition> take resource elements as their children, observing the status of them loading
<Suspense> and <Transition> is the former one causes flickering every time the data reloaded whereas the latter one only shows the fallback the first time<Async> is the no fallback version of <Suspense> that helps omit a bit of boilerplatessea-orm-cli migrate init
It generates a start-up Rust lib dir migration at the working dir, and you can set up migration code there
After you've done setting it up, execute this command:
sea-orm-cli generate entity -u postgres://postgres:postgres@localhost:5432/postgres -o entity/src
style/input.css on style/output.css by executing this command:tailwindcss -i style/input.css -o style/output.css --watch
--watch mode, changes will be reflected soon after you've made in style/input.css