diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1ab01ef..c8f8d3d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v0.3.0 +- `update` function now takes a mutable ref of the model. (Breaking) +- `Update` (update's return type) is now a struct. (Breaking) +- Async, etc events are now handled through messages, instead of passing `App` +through the view func. (breaking) +- Fixed some bugs with empty elements +- Internal code cleanup +- Added commented-out release command to example build files +- Added more tests + ## v0.2.10 - Routing can be triggered by clicking any element containing a `Href` attribute with value as a relative link diff --git a/Cargo.toml b/Cargo.toml index 82b672918..a27f2bd3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "seed" -version = "0.2.10" +version = "0.3.0" description = "A Rust framework for creating web apps, using WebAssembly" authors = ["DavidOConnor "] license = "MIT" diff --git a/README.md b/README.md index 92ed4f785..03161a0e6 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,14 @@ crate-type = ["cdylib"] [dependencies] seed = "^0.2.4" -wasm-bindgen = "^0.2.33" +wasm-bindgen = "^0.2.38" web-sys = "^0.3.6" ``` ## A short example Here's an example demonstrating structure and syntax; it can be found in working form -under `examples/counter`. Descriptions of its parts are in the +in the [counter example](https://github.com/David-OConnor/seed/tree/master/examples/counter) +Descriptions of its parts are in the Guide section below. Its structure follows [The Elm Architecture](https://guide.elm-lang.org/architecture/). *lib.rs*: @@ -119,13 +120,14 @@ enum Msg { ChangeWWC(String), } -/// The sole source of updating the model; returns a fresh one. -fn update(msg: Msg, model: Model) -> Update { +/// The sole source of updating the model +fn update(msg: Msg, model: &mut Model) -> Update { match msg { - Msg::Increment => Render(Model {count: model.count + 1, ..model}), - Msg::Decrement => Render(Model {count: model.count - 1, ..model}), - Msg::ChangeWWC(what_we_count) => Render(Model {what_we_count, ..model }) + Msg::Increment => model.count += 1, + Msg::Decrement => model.count -= 1, + Msg::ChangeWWC(what_we_count) => model.what_we_count = what_we_count, } + Render.into() } @@ -143,7 +145,7 @@ fn success_level(clicks: i32) -> El { } /// The top-level component we pass to the virtual dom. -fn view(state: seed::App, model: &Model) -> El { +fn view(model: &Model) -> El { let plural = if model.count == 1 {""} else {"s"}; // Attrs, Style, Events, and children may be defined separately. @@ -220,7 +222,7 @@ navigate to that folder in a terminal, run the build script for your system (`build.sh` or `build.ps1`), then start a dev server as described above. Note that if you copy an example to a separate folder, you'll need to edit its `Cargo.toml` to point to the package on [crates.io](https://crates.io) instead of locally: Ie replace -`seed = { path = "../../"` with `seed = "^0.2.4"`, and in the build script, remove the leading `../../` on the second +`seed = { path = "../../"` with `seed = "^0.3.0"`, and in the build script, remove the leading `../../` on the second line. diff --git a/examples/server_integration/README.md b/examples/server_integration/README.md index b5a79be42..9558ed097 100644 --- a/examples/server_integration/README.md +++ b/examples/server_integration/README.md @@ -2,4 +2,7 @@ A demonstration of sharing data structures between client and server when using a Rust backend. This reduces duplication. Also provides examples of a simple get request. - Uses Rocket for the backend. See the Guide for details. \ No newline at end of file + Uses Rocket for the backend. + + To run, from this directory, run `cargo +nightly run`, and from the `frontend` + subdirectory, run the build script and dev server as you would normally. \ No newline at end of file diff --git a/examples/server_integration/frontend/build.ps1 b/examples/server_integration/frontend/build.ps1 index 5070ce4d2..157bf6b1d 100644 --- a/examples/server_integration/frontend/build.ps1 +++ b/examples/server_integration/frontend/build.ps1 @@ -1,5 +1,5 @@ cargo build --target wasm32-unknown-unknown -wasm-bindgen ../../../target/wasm32-unknown-unknown/debug/server_interaction.wasm --no-modules --out-dir ./pkg --out-name package +wasm-bindgen ./target/wasm32-unknown-unknown/debug/frontend.wasm --no-modules --out-dir ./pkg --out-name package #cargo build --target wasm32-unknown-unknown --release -#wasm-bindgen ../../../target/wasm32-unknown-unknown/release/server_interaction.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file +#wasm-bindgen ./target/wasm32-unknown-unknown/release/frontend.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file diff --git a/examples/server_integration/frontend/build.sh b/examples/server_integration/frontend/build.sh index defd5c4e7..668f324ad 100755 --- a/examples/server_integration/frontend/build.sh +++ b/examples/server_integration/frontend/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash cargo build --target wasm32-unknown-unknown -wasm-bindgen ../../../target/wasm32-unknown-unknown/debug/frontend.wasm --no-modules --out-dir ./pkg --out-name package +wasm-bindgen ./target/wasm32-unknown-unknown/debug/frontend.wasm --no-modules --out-dir ./pkg --out-name package #cargo build --target wasm32-unknown-unknown --release -#wasm-bindgen ../../../target/wasm32-unknown-unknown/release/frontend.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file +#wasm-bindgen ./target/wasm32-unknown-unknown/release/frontend.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file diff --git a/examples/server_integration/frontend/src/lib.rs b/examples/server_integration/frontend/src/lib.rs index 1057382f1..84f76af46 100644 --- a/examples/server_integration/frontend/src/lib.rs +++ b/examples/server_integration/frontend/src/lib.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate seed; use seed::prelude::*; -use seed::{spawn_local, Method, Request}; +use seed::{Method, Request}; use futures::Future; @@ -28,7 +28,7 @@ fn get_data() -> impl Future { #[derive(Clone)] enum Msg { - GetData(seed::App), + GetData, Replace(Data), OnFetchErr(JsValue), } @@ -55,7 +55,7 @@ fn view(model: &Model) -> El { div![ h1![format!("Val: {} Text: {}", model.data.val, model.data.text)], button![ - raw_ev("click", move |_| Msg::GetData()), + raw_ev("click", move |_| Msg::GetData), "Update data" ] ] diff --git a/examples/server_integration/shared/src/lib.rs b/examples/server_integration/shared/src/lib.rs index 5123081c2..87c0a8066 100644 --- a/examples/server_integration/shared/src/lib.rs +++ b/examples/server_integration/shared/src/lib.rs @@ -1,6 +1,6 @@ use serde::{Serialize, Deserialize}; -#[derive(Default, Serialize, Deserialize)] +#[derive(Clone, Default, Serialize, Deserialize)] pub struct Data { pub val: i8, pub text: String, diff --git a/examples/websocket/README.md b/examples/websocket/README.md index d5815be02..0ebdbb187 100644 --- a/examples/websocket/README.md +++ b/examples/websocket/README.md @@ -1,6 +1,6 @@ ## Communicating with a server using WebSocket Inlcludes an example Rust server (not related to Seed), and client. Both share datastructures -in `json.rs`. To run, run `cargo run` in one terminal, and `python serve.py` in another. +in `json.rs`. To run, build as normal, run `cargo run` in one terminal, and `python serve.py` in another. Written by Flosse. \ No newline at end of file