[][src]Crate yew

Yew Framework - API Documentation

Yew is a framework for web-client apps created with a modern Rust-to-Wasm compilation feature. This framework was highly inspired by Elm and React.

Minimal example:

#[macro_use]
extern crate yew;
use yew::prelude::*;

struct Model {
    value: i64,
}

enum Msg {
    DoIt,
}

impl Component for Model {
    type Message = Msg;
    type Properties = ();
    fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
        Self {
            value: 0,
        }
    }

    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        match msg {
            Msg::DoIt => self.value = self.value + 1
        }
        true
    }
}

impl Renderable<Model> for Model {
    fn view(&self) -> Html<Self> {
        html! {
            <div>
               <button onclick=|_| Msg::DoIt,>{ "+1" }</button>
                <p>{ self.value }</p>
            </div>
        }
    }
}

fn main() {
    yew::initialize();
    App::<Model>::new().mount_to_body();
    yew::run_loop();
}

Modules

agent

This module contains types to support multi-threading in Yew.

app

This module contains App sctruct which used to bootstrap a component in an isolated scope.

callback

This module contains structs to interact with Scopes.

components

This module contains useful components. At this moment it includes typed Select only.

format

Utility module to convert data to types and back by specific formats like: JSON, BSON, TOML, YAML, XML.

html

The main module which contents aliases to necessary items to create a template and implement update and view functions. Also this module contains declaration of Component trait which used to create own UI-components.

macros

This module contains macros which implements html! macro and JSX-like templates.

prelude

The Yew Prelude

scheduler

This module contains a scheduler.

services

This module is a container of servies to interact with the external resources.

virtual_dom

This module contains the implementation of reactive virtual dom concept.

Macros

html

This macro implements JSX-like templates.

html_impl

The html! entrypoint and this implementation had to be separated to prevent infinite recursion.

Functions

initialize

Initializes yew framework. It should be called first.

run_loop

Starts event loop.