Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web-sys examples/tests conversion #841

Merged
merged 12 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ install:
script:
- ./ci/run_checks.sh
- CHROMEDRIVER=$(pwd)/chromedriver ./ci/run_tests.sh
# - CHROMEDRIVER=$(pwd)/chromedriver ./ci/check_examples.sh
- CHROMEDRIVER=$(pwd)/chromedriver ./ci/check_examples.sh
8 changes: 4 additions & 4 deletions ci/check_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ cd examples/showcase

if [ "$emscripten_supported" == "0" ]; then
# TODO - Emscripten builds are broken on rustc > 1.39.0
cargo web build --target asmjs-unknown-emscripten
cargo web build --target wasm32-unknown-emscripten
cargo web build --target asmjs-unknown-emscripten --features std_web
cargo web build --target wasm32-unknown-emscripten --features std_web
fi

# TODO showcase doesn't support wasm-bindgen yet
cargo web build --target wasm32-unknown-unknown
cargo web build --target wasm32-unknown-unknown --features std_web
cargo build --target wasm32-unknown-unknown --features web_sys

# Reset cwd
cd ../..
30 changes: 20 additions & 10 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
[workspace]
members = [
"counter",
"crm",
"custom_components",
"dashboard",
"node_refs",
"file_upload",
"fragments",
"futures",
"game_of_life",
"inner_html",
"js_callback",
"large_table",
"minimal",
"mount_point",
"multi_thread",
"nested_list",
"npm_and_rest",
"server",
"showcase",
"textarea",
"timer",
"todomvc",
"two_apps",
"std_web/counter",
"std_web/file_upload",
"std_web/inner_html",
"std_web/js_callback",
"std_web/mount_point",
"std_web/multi_thread",
"std_web/node_refs",
"std_web/npm_and_rest",
"std_web/todomvc",
"std_web/two_apps",
"web_sys/counter",
"web_sys/file_upload",
"web_sys/inner_html",
"web_sys/js_callback",
"web_sys/mount_point",
"web_sys/multi_thread",
"web_sys/node_refs",
"web_sys/npm_and_rest",
"web_sys/todomvc",
"web_sys/two_apps",
]
114 changes: 94 additions & 20 deletions examples/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,102 @@ function ctrl_c() {
kill $PID
}

function build() {
function build_std_web() {
for example in */ ; do
if [[ $example == server* ]]; then
continue
fi
echo "Building: $example"
cd $example
cargo update
cargo web build --target wasm32-unknown-unknown
cd ..
if [[ $example == static* ]]; then
daxpedda marked this conversation as resolved.
Show resolved Hide resolved
continue
fi
if [[ $example == web_sys* ]]; then
continue
fi
if [[ $example == std_web* ]]; then
build_std_web()
else
echo "Building: $example"
cd $example
cargo update
cargo web build --target wasm32-unknown-unknown
cd ..
fi
done
}

function build_web_sys() {
for example in */ ; do
if [[ $example == server* ]]; then
continue
fi
if [[ $example == static* ]]; then
continue
fi
if [[ $example == std_web* ]]; then
continue
fi
if [[ $example == web_sys* ]]; then
build_web_sys()
else
echo "Building: $example"
cd $example
cargo update
cargo build --target wasm32-unknown-unknown
wasm-bindgen --target web --no-typescript --out-dir ../static/ --out-name wasm ../target/wasm32-unknown-unknown/debug/$example.wasm
cd ..
fi
done
}

function run() {
function run_std_web() {
trap ctrl_c INT
for example in */ ; do
if [[ $example == server* ]]; then
continue
fi
echo "Running: $example"
cd $example
cargo web start --target wasm32-unknown-unknown &
PID=$!
wait $PID
cd ..
if [[ $example == static* ]]; then
continue
fi
if [[ $example == web_sys* ]]; then
continue
fi
if [[ $example == std_web* ]]; then
run_std_web()
else
echo "Running: $example"
cd $example
cargo web start --target wasm32-unknown-unknown &
PID=$!
wait $PID
cd ..
fi
done
}

function run_web_sys() {
trap ctrl_c INT
for example in */ ; do
if [[ $example == server* ]]; then
continue
fi
if [[ $example == static* ]]; then
continue
fi
if [[ $example == std_web* ]]; then
continue
fi
if [[ $example == web_sys* ]]; then
run_web_sys()
else
echo "Running: $example"
cd $example
cargo build --target wasm32-unknown-unknown
wasm-bindgen --target web --no-typescript --out-dir ../static/ --out-name wasm ../target/wasm32-unknown-unknown/debug/$example.wasm
http -r ../static/
PID=$!
wait $PID
cd ..
fi
done
}

Expand All @@ -51,16 +122,19 @@ case "$1" in
--help)
echo "Available commands: build, run, clean"
;;
build)
build
build_std_web)
build_std_web
;;
build_web_sys)
build_web_sys
;;
run)
run
run_std_web)
run_std_web
;;
run_web_sys)
run_web_sys
;;
clean)
clean
;;
*)
build
;;
esac
3 changes: 0 additions & 3 deletions examples/counter/src/main.rs

This file was deleted.

4 changes: 4 additions & 0 deletions examples/crm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ serde = "1"
serde_derive = "1"
yew = { path = "../.." }
pulldown-cmark = "0.1.2"

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
2 changes: 1 addition & 1 deletion examples/crm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Component for Model {
type Properties = ();

fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
let storage = StorageService::new(Area::Local);
let storage = StorageService::new(Area::Local).expect("storage was disabled by the user");
let Json(database) = storage.restore(KEY);
let database = database.unwrap_or_else(|_| Database {
clients: Vec::new(),
Expand Down
4 changes: 4 additions & 0 deletions examples/custom_components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2018"

[dependencies]
yew = { path = "../.." }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
4 changes: 4 additions & 0 deletions examples/dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ anyhow = "1"
serde = "1"
serde_derive = "1"
yew = { path = "../..", features = ["toml"] }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
8 changes: 4 additions & 4 deletions examples/dashboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ impl Model {
);
let request = Request::get("/data.json").body(Nothing).unwrap();
if binary {
self.fetch_service.fetch_binary(request, callback)
self.fetch_service.fetch_binary(request, callback).unwrap()
} else {
self.fetch_service.fetch(request, callback)
self.fetch_service.fetch(request, callback).unwrap()
}
}

Expand All @@ -112,9 +112,9 @@ impl Model {
);
let request = Request::get("/data.toml").body(Nothing).unwrap();
if binary {
self.fetch_service.fetch_binary(request, callback)
self.fetch_service.fetch_binary(request, callback).unwrap()
} else {
self.fetch_service.fetch(request, callback)
self.fetch_service.fetch(request, callback).unwrap()
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions examples/file_upload/src/main.rs

This file was deleted.

4 changes: 4 additions & 0 deletions examples/fragments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2018"

[dependencies]
yew = { path = "../.." }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
6 changes: 5 additions & 1 deletion examples/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ yew = { path = "../.." }
wasm-bindgen-futures = "0.4.3"

[dependencies.web-sys]
version = "0.3.30"
version = "0.3.35"
features = [
'Headers',
'Request',
Expand All @@ -27,3 +27,7 @@ features = [

[target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'.dependencies]
wasm-bindgen = "0.2.58"

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
4 changes: 2 additions & 2 deletions examples/futures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Because this example uses features not allowed by cargo web, it cannot be includ
This example requires rustc v1.39.0 or above to compile due to its use of async/.await syntax.

```sh
wasm-pack build --target web && rollup ./main.js --format iife --file ./pkg/bundle.js && python -m SimpleHTTPServer 8080
wasm-pack build --target web --out-dir ../static/ --out-name wasm -- --features (web_sys|std_web) && python -m SimpleHTTPServer 8080
```
This will compile the project, bundle up the compiler output and static assets, and start a http server on port 8080 so you can access the example at localhost:8080.

It is expected that you have a setup with wasm-pack, rollup, and python installed.
It is expected that you have a setup with wasm-pack and python installed.
10 changes: 0 additions & 10 deletions examples/futures/index.html

This file was deleted.

6 changes: 0 additions & 6 deletions examples/futures/main.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Component for Model {
}
}

#[wasm_bindgen]
#[wasm_bindgen(start)]
pub fn run_app() {
yew::start_app::<Model>();
}
8 changes: 6 additions & 2 deletions examples/game_of_life/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ authors = ["Diego Cardoso <dige0card0s0@hotmail.com>",
edition = "2018"

[dependencies]
rand = { version = "0.6.5", features = ["stdweb"] }
rand = "0.6.5"
log = "0.4"
web_logger = "0.1"
web_logger = "0.2"
yew = { path = "../.." }

[features]
std_web = ["rand/stdweb", "yew/std_web"]
web_sys = ["rand/wasm-bindgen", "yew/web_sys"]
9 changes: 0 additions & 9 deletions examples/inner_html/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/js_callback/src/main.rs

This file was deleted.

4 changes: 4 additions & 0 deletions examples/large_table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2018"

[dependencies]
yew = { path = "../.." }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
4 changes: 4 additions & 0 deletions examples/minimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2018"

[dependencies]
yew = { path = "../.." }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]
9 changes: 0 additions & 9 deletions examples/mount_point/Cargo.toml

This file was deleted.

Loading