Full Stack Developer
Twitch Streaming:
Awesome Hoodie Collection
Former Snowboard Bum
Yew is a modern Rust framework for creating multi-threaded front-end web apps with WebAssembly.
a binary instruction format for a stack-based virtual machine
a portable compilation target for programming languages
https://github.com/appcypher/awesome-wasm-langs
UI:
Generic:
Make sure you have Rust and Cargo
Get some tooling
Minimal Template: wasm-pack and rollup
Webpack Template: wasm-pack and webpack
https://github.com/yewstack/yew/tree/master/examples
Best places to start:
Beware! Recursion Limit Error Prone
pub struct Container(Props);
#[derive(Properties, Clone)]
pub struct Props {
pub children: Children,
#[props_or_default]
pub some_string,
#[props_or_(true)]
pub some_boolean,
}
impl Component for Container {
type Properties = Props;
fn view(&self) -> Html {
html! {
<div id="container">
{ self.0.children.render() }
</div>
}
}
}
pub struct Container{
props: Props,
link: ComponentLink<Self>,
}
#[derive(Properties, Clone)]
pub struct Props { }
#[derive(Clone, PartialEq)]
pub enum Msg {
Reset,
HandleClick,
HandleInput(event)
}
impl Component for Container {
type Properties = Props;
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
Self {
props,
link,
}
}
fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::HandleClick => {
info!("HANDLING CLICK");
}
Msg::HandleInput(input_value) => {
info!("HANDLING INPUT {:?}", input_value);
}
}
true
}
fn view(&self) -> Html {
html! {
<div id="container">
<input
oninput=self.link.callback(|event: InputData| Msg::handleInput(event.value))
/>
<button
onclick=self.link.callback(|_| Msg::handleClick)
>{"Click Me"}</button>
</div>
}
}
}
Similar to Angular Services
Uses web-workers for concurrency
Useful for:
Bridge: bi-directional communication
Dispatcher: unidirectional
Used to abstract Browser APIs
fn fetch_json(&mut self, binary: AsBinary) -> yew::services::fetch::FetchTask {
let callback = self.link.callback(
move |response: Response<Json<Result<DataFromFile, Error>>>| {
// Handle response
},
);
let request = Request::get("/data.json").body(Nothing).unwrap();
FetchService::fetch(request, callback).unwrap()
}
}
web-sys <-> wasm-bindgen
stdweb <-> cargo-web
console_error_panic
: nicer stacktraces
log
: rust standard crate just works
ConsoleService
: Yew wrapper service
NeqAssign: shallow prop checks
PureComponent: uses NeqAssign (memoized based on props)
Lrc: linked list reference counted smart pointer
Mrc/Irc: Mutable/Immutable reference counted smart pointers
History: A history tracking wrapper that uses a VecDeque
Component lifecycle state machine
VDOM diff algorithm
wee_alloc
: The Wasm-Enabled, Elfin Allocator.
Elfin, i.e. small:
WebAssembly enabled: Designed for the wasm32-unknown-unknown target and #[no_std].
Cargo Workspaces
make your main crate handle routing/page selection
move all commonly shared code to another crate
make a different crate for each page
https://github.com/yewstack/yew/issues/533
yew_css (inline declarations)
css-in-rust (inspired by sass and styled components)
css-modules
wasm-bindgen-test
Needed (according to docs site)
Yewtify seems promising
https://github.com/flosse/rust-web-framework-comparison#frontend-frameworks-wasm
Notables