Crate yew_stdweb

Source
Expand description

§Yew Framework - API Documentation

Yew is a modern Rust framework for creating multi-threaded front-end web apps using WebAssembly

  • Features a macro for declaring interactive HTML with Rust expressions. Developers who have experience using JSX in React should feel quite at home when using Yew.
  • Achieves high performance by minimizing DOM API calls for each page render and by making it easy to offload processing to background web workers.
  • Supports JavaScript interoperability, allowing developers to leverage NPM packages and integrate with existing JavaScript applications.

§Supported Targets

  • wasm32-unknown-unknown
  • wasm32-unknown-emscripten
  • asmjs-unknown-emscripten

§Important Notes

  • Yew is not (yet) production ready but is great for side projects and internal tools
  • We recommend aliasing yew-stdweb to yew in your Cargo.toml: yew = { package = "yew-stdweb", .. }
  • If your app is built with web-sys, we recommend using yew instead.

§Example

use yew::prelude::*;

enum Msg {
    AddOne,
}

struct Model {
    link: ComponentLink<Self>,
    value: i64,
}

impl Component for Model {
    type Message = Msg;
    type Properties = ();

    fn create(_props: Self::Properties, link: ComponentLink<Self>) -> Self {
        Self {
            link,
            value: 0,
        }
    }

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

    fn change(&mut self, _props: Self::Properties) -> ShouldRender {
        false
    }

    fn view(&self) -> Html {
        html! {
            <div>
                <button onclick=self.link.callback(|_| Msg::AddOne)>{ "+1" }</button>
                <p>{ self.value }</p>
            </div>
        }
    }
}

fn main() {
    yew::start_app::<Model>();
}

Re-exports§

Modules§

  • This module contains types to support multi-threading and state management.
  • This module contains the App struct, which is used to bootstrap a component in an isolated scope.
  • This module contains data types for interacting with Scopes.
  • The module that contains all events available in the framework.
  • Utility module to convert data to types and back by specific formats like: JSON, BSON, TOML, YAML, XML.
  • The main html module which defines components, listeners, and class helpers.
  • This module contains macros which implements html! macro and JSX-like templates
  • The Yew Prelude
  • This module is a container of servies to interact with the external resources.
  • This module contains useful utilities to get information about the current document.
  • This module contains Yew’s implementation of a reactive virtual DOM.

Macros§

  • This macro is used for a format that can be encoded as Binary. It is used in conjunction with a type definition for a tuple struct with one (publicly accessible) element of a generic type. Not all types that can be encoded as Binary can be encoded as Text. As such, this macro should be paired with the text_format macro where such an encoding works (e.g., JSON), or with the text_format_is_an_error macro for binary-only formats (e.g., MsgPack).
  • This macro provides a convenient way to create Classes.
  • This macro implements JSX-like templates.
  • This macro is similar to html!, but preserves the component type instead of wrapping it in Html.
  • Build Properties outside of the html! macro.
  • This macro is used for a format that can be encoded as Text. It is used in conjunction with a type definition for a tuple struct with one (publically accessible) element of a generic type. Since any type that can be encoded as Text can also be encoded as Binary, it should be used with the binary_format macro.
  • This macro is used for a format that can be encoded as Binary but can’t be encoded as Text. It is used in conjunction with a type definition for a tuple struct with one (publically accessible) element of a generic type. This macro should be paired with the binary_format macro that defines the binary-only format.

Functions§