From b7a32a2096b16d8c3eba3c404039829225779365 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 3 May 2020 06:45:36 +0200 Subject: [PATCH] Include Counter Example at home page of generated documentation. --- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0124bc126..dcb3396e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,50 @@ //! Visit the [website](https://seed-rs.org/) //! //! See the [github Readme](https://github.com/seed-rs/seed) for details +//! +//! +//! ## Counter Example +//! ``` +//! use seed::{prelude::*, *}; +//! +//! // `init` describes what should happen when your app started. +//! fn init(_: Url, _: &mut impl Orders) -> Model { +//! Model::default() +//! } +//! +//! // `Model` describes our app state. +//! type Model = i32; +//! +//! // `Msg` describes the different events you can modify state with. +//! enum Msg { +//! Increment, +//! } +//! +//! // `update` describes how to handle each `Msg`. +//! fn update(msg: Msg, model: &mut Model, _: &mut impl Orders) { +//! match msg { +//! Msg::Increment => *model += 1, +//! } +//! } +//! +//! // `view` describes what to display. +//! fn view(model: &Model) -> Node { +//! div![ +//! "This is a counter: ", +//! C!["counter"], +//! button![ +//! model, +//! ev(Ev::Click, |_| Msg::Increment), +//! ], +//! ] +//! } +//! +//! #[wasm_bindgen(start)] +//! pub fn start() { +//! // Mount the `app` to the element with the `id` "app". +//! App::start("app", init, update, view); +//! } +//! ``` //#![deny(missing_docs)] #![forbid(unsafe_code)]