Seed codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Seed including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Seed community styleguides & best practices.
For more information on how to this works with other frontends/backends, head over to the RealWorld repo.
NOTE: This project uses older Seed version 0.5.1
. It will be updated and refactored once Seeder is ready. Please see built-in examples and other projects instead.
I think the best way to show you how it works is to describe what's going on step by step when you open this example in your browser. So let's say you've just written https://seed-rs-realworld.netlify.com/
to URL bar and pressed Enter:
index.html
. (See /netlify.toml
.)/index.html
that loads wasm
file and starts application./src/lib.rs
- see block Start
at the end of that file.before_mount
(we are still in file lib.rs
):
.mount_point("element-id")
. But the default one (app
) is good for us..mount_type(MountType::Takeover)
means that the previous HTML content in the mount point will be replaced with the application HTML.after_mount
is called:
Viewer
from the local storage. Viewer
is the object that contains info about currently logged in user (name, auth. token, avatar image url, etc).Session
with Viewer
(or without it if you are not logged in). Session
is de facto shared state - you are able to get it from all pages.Model
is created with Session
. Model
is enum, where each variant represents one page. Here, in init
function, we create Model
from variant Redirect
because we haven't decided yet which page to show (i.e. Redirect
is a "placeholder" variant).after_mount
function also sends message RouteChanged
which is handled in update
function. Handler calls function change_model_by_route
which choose the right Model
according to the URL path.Model::Home
is chosen in our example. However this variant should contain "sub-model" from /src/page/home
so we need to call page::home::init(..)
to get it.page::home::init
loads required data (e.g. article feed or tags).View
function again we can see it rendered in the browser.We didn't talked about function sink
in lib.rs
in the steps above. sink
has the similar purpose like update
function but it handles global messages. It's the way how modules communicate with parents or with other modules. The most use case is to send GMsg::RoutePushed
when we want to go to another page (see function go_to
in /src/route.rs
).
$ rustup update
$ rustup target add wasm32-unknown-unknown
$ cargo install --force cargo-make
$ cargo make all
or $ cargo make watch
pkg-config
on Linux - just follow recommendations after compilation errors.$ cargo make serve
$ cargo make watch
.master
and run $ cargo make verify
(+ commit changes, if any) before creating PR.$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
HTML 1 21 19 2 0
Markdown 1 66 66 0 0
Rust 81 5899 4869 344 686
SVG 1 17 17 0 0
TOML 4 199 146 20 33
-------------------------------------------------------------------------------
Total 88 6202 5117 366 719
-------------------------------------------------------------------------------