Skip to content

Commit

Permalink
Prep for 0.3.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Mar 13, 2019
1 parent 2a79c70 commit e073bb9
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <david.alan.oconnor@gmail.com>"]
license = "MIT"
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*:
Expand Down Expand Up @@ -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<Msg, Model> {
/// The sole source of updating the model
fn update(msg: Msg, model: &mut Model) -> Update<Msg> {
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()
}


Expand All @@ -143,7 +145,7 @@ fn success_level(clicks: i32) -> El<Msg> {
}

/// The top-level component we pass to the virtual dom.
fn view(state: seed::App<Msg, Model>, model: &Model) -> El<Msg> {
fn view(model: &Model) -> El<Msg> {
let plural = if model.count == 1 {""} else {"s"};

// Attrs, Style, Events, and children may be defined separately.
Expand Down Expand Up @@ -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.


Expand Down
5 changes: 4 additions & 1 deletion examples/server_integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
4 changes: 2 additions & 2 deletions examples/server_integration/frontend/build.ps1
Original file line number Diff line number Diff line change
@@ -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
#wasm-bindgen ./target/wasm32-unknown-unknown/release/frontend.wasm --no-modules --out-dir ./pkg --out-name package
4 changes: 2 additions & 2 deletions examples/server_integration/frontend/build.sh
Original file line number Diff line number Diff line change
@@ -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
#wasm-bindgen ./target/wasm32-unknown-unknown/release/frontend.wasm --no-modules --out-dir ./pkg --out-name package
6 changes: 3 additions & 3 deletions examples/server_integration/frontend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -28,7 +28,7 @@ fn get_data() -> impl Future<Item = Msg, Error = Msg> {

#[derive(Clone)]
enum Msg {
GetData(seed::App<Msg, Model>),
GetData,
Replace(Data),
OnFetchErr(JsValue),
}
Expand All @@ -55,7 +55,7 @@ fn view(model: &Model) -> El<Msg> {
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"
]
]
Expand Down
2 changes: 1 addition & 1 deletion examples/server_integration/shared/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit e073bb9

Please # to comment.