diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index d9c5a4d57..000000000 --- a/.rustfmt.toml +++ /dev/null @@ -1,2 +0,0 @@ -report_todo = "Unnumbered" -report_fixme = "Unnumbered" diff --git a/.travis.yml b/.travis.yml index bc81ad548..9aa19cb48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,6 @@ install: - ./ci/install_cargo_web.sh script: - - ./ci/run_checks.sh + - ./ci/run_stable_checks.sh - GECKODRIVER=$(pwd)/geckodriver ./ci/run_tests.sh - - ./ci/check_examples.sh + - ./ci/run_emscripten_checks.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 438227ae0..4980e6398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -404,7 +404,7 @@ cloned is when a wrapper component re-renders nested children components. - #### ⚡️ Features - - `Future` support :tada: A `Component` can update following the completion of a `Future`. Check out [this example](https://github.com/yewstack/yew/tree/master/examples/futures) to see how it works. This approach was borrowed from a fork of Yew called [`plaster`](https://github.com/carlosdp/plaster) created by [@carlosdp]. [[@hgzimmerman], [#717](https://github.com/yewstack/yew/pull/717)] + - `Future` support :tada: A `Component` can update following the completion of a `Future`. Check out [this example](https://github.com/yewstack/yew/tree/v0.14.0/examples/futures) to see how it works. This approach was borrowed from a fork of Yew called [`plaster`](https://github.com/carlosdp/plaster) created by [@carlosdp]. [[@hgzimmerman], [#717](https://github.com/yewstack/yew/pull/717)] - Added the `agent` and `services` features so that this functionality can be disabled (useful if you are switching to using `Future`s). [[@hgzimmerman], [#684](https://github.com/yewstack/yew/pull/684)] - Add `ref` keyword for allowing a `Component` to have a direct reference to its rendered elements. For example, you can now easily focus an `` element after mounting. [[@jstarry], [#715](https://github.com/yewstack/yew/pull/715)] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fd0a19e1..200daa1d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,31 +8,25 @@ rustup target add wasm32-unknown-unknown ``` -#### Install [cargo-web] +#### Build -This is an optional tool that simplifies running the examples: +```bash +cargo build --target wasm32-unknown-unknown +``` + +#### Examples + +TODO: Add more info + +##### stdweb +In order to run the examples in `./yew-stdweb`, you may wish to install [cargo-web]: ```bash cargo install cargo-web ``` -> Add `--force` option to ensure you install the latest version. - [cargo-web]: https://github.com/koute/cargo-web -#### Build - -Either -```bash -cargo build --target wasm32-unknown-unknown --features web_sys -``` -or -```bash -cargo build --target wasm32-unknown-unknown --features std_web -``` -See more about features [here](https://docs.rs/yew/0.14.0/yew/#important-notes) - - #### Test ##### Web Tests @@ -48,9 +42,9 @@ although more driver support may be added! You can download these at: * safaridriver - should be preinstalled on OSX ##### Macro Tests -When adding or updating tests, please make sure you have updated the appropriate `stderr` file, which you can find [here](https://github.com/yewstack/yew/tree/master/crates/macro/tests/macro) for the `html!` macro. These files ensure that macro compilation errors are correct and easy to understand. +When adding or updating tests, please make sure you have updated the appropriate `stderr` file, which you can find [here](https://github.com/yewstack/yew/tree/master/yew-macro/tests/macro) for the `html!` macro. These files ensure that macro compilation errors are correct and easy to understand. -To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo test --test macro_test` or `TRYBUILD=overwrite cargo test --test derive_props_test` from the `crates/macro` directory. +To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo test --test macro_test` or `TRYBUILD=overwrite cargo test --test derive_props_test` from the `yew-macro` directory. ##### Running Tests @@ -60,10 +54,5 @@ To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo or ```bash -cargo test --target wasm32-unknown-unknown --features wasm_test --features web_sys -``` -or - -```bash -cargo test --target wasm32-unknown-unknown --features wasm_test --features std_web +cargo test --target wasm32-unknown-unknown --features wasm_test ``` diff --git a/Cargo.toml b/Cargo.toml index 5813644c7..2792bfe31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,142 +1,32 @@ -[package] -name = "yew" -version = "0.14.3" -edition = "2018" -authors = [ - "Denis Kolodin ", - "Justin Starry ", -] -repository = "https://github.com/yewstack/yew" -homepage = "https://github.com/yewstack/yew" -documentation = "https://docs.rs/yew/" -license = "MIT/Apache-2.0" -readme = "README.md" -keywords = ["web", "asmjs", "webasm", "javascript"] -categories = ["gui", "web-programming"] -description = "A framework for making client-side single-page apps" - -[badges] -travis-ci = { repository = "yewstack/yew" } - -[dependencies] -anyhow = "1" -anymap = "0.12" -bincode = { version = "~1.2.1", optional = true } -cfg-if = "0.1" -cfg-match = "0.2" -console_error_panic_hook = { version = "0.1", optional = true } -futures = { version = "0.3", optional = true } -gloo = { version = "0.2.1", optional = true } -http = "0.2" -indexmap = "1.0.2" -js-sys = { version = "0.3", optional = true } -log = "0.4" -proc-macro-hack = "0.5" -proc-macro-nested = "0.1" -rmp-serde = { version = "0.14.0", optional = true } -serde = { version = "1.0", features = ["derive"] } -serde_cbor = { version = "0.11.1", optional = true } -serde_json = "1.0" -serde_yaml = { version = "0.8.3", optional = true } -slab = "0.4" -stdweb = { version = "0.4.20", optional = true } -thiserror = "1" -toml = { version = "0.5", optional = true } -wasm-bindgen = { version = "0.2.60", optional = true } -wasm-bindgen-futures = { version = "0.4", optional = true } -yew-macro = { version = "0.14.1", path = "crates/macro" } - -[dependencies.web-sys] -version = "0.3" -optional = true -features = [ - "AbortController", - "AbortSignal", - "BinaryType", - "Blob", - "BlobPropertyBag", - "console", - "DedicatedWorkerGlobalScope", - "Document", - "DomTokenList", - "DragEvent", - "Element", - "Event", - "EventTarget", - "File", - "FileList", - "FileReader", - "FocusEvent", - "Headers", - "HtmlElement", - "HtmlInputElement", - "HtmlSelectElement", - "HtmlTextAreaElement", - "KeyboardEvent", - "Location", - "MessageEvent", - "MouseEvent", - "Node", - "ObserverCallback", - "PointerEvent", - "ReferrerPolicy", - "Request", - "RequestCache", - "RequestCredentials", - "RequestInit", - "RequestMode", - "RequestRedirect", - "Response", - "Storage", - "Text", - "TouchEvent", - "UiEvent", - "Url", - "WebSocket", - "WheelEvent", - "Window", - "Worker", - "WorkerGlobalScope", - "WorkerOptions", -] - -# Changes here must be reflected in `build.rs` -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] -wasm-bindgen = "0.2.60" - -# Changes here must be reflected in `build.rs` -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies] -wasm-bindgen-test = "0.3.4" -base64 = "0.12.0" -ssri = "5.0.0" - -[target.'cfg(target_os = "emscripten")'.dependencies] -ryu = "1.0.2" # 1.0.1 breaks emscripten - -[dev-dependencies] -serde_derive = "1" -trybuild = "1.0" -rustversion = "1.0" -rmp-serde = "0.14.0" -bincode = "~1.2.1" - -[features] -default = ["services", "agent"] -std_web = ["stdweb"] -web_sys = ["console_error_panic_hook", "futures", "gloo", "js-sys", "web-sys", "wasm-bindgen", "wasm-bindgen-futures"] -doc_test = [] -wasm_test = [] -services = [] -agent = ["bincode"] -yaml = ["serde_yaml"] -msgpack = ["rmp-serde"] -cbor = ["serde_cbor"] - -[package.metadata.docs.rs] -features = ["web_sys", "agent", "services", "yaml", "cbor", "toml", "msgpack", "doc_test"] - [workspace] members = [ - "crates/macro", - "crates/functional", + "yew", + "yew-functional", + "yew-macro", + + # Examples + "examples/counter", + "examples/crm", + "examples/custom_components", + "examples/dashboard", + "examples/file_upload", + "examples/fragments", + "examples/futures", + "examples/game_of_life", + "examples/inner_html", + "examples/js_callback", + "examples/large_table", + "examples/minimal", + "examples/mount_point", + "examples/multi_thread", + "examples/nested_list", + "examples/node_refs", + "examples/npm_and_rest", + "examples/pub_sub", + "examples/server", + "examples/textarea", + "examples/timer", + "examples/todomvc", + "examples/two_apps", + "examples/webgl", ] diff --git a/ci/check_examples.sh b/ci/check_examples.sh deleted file mode 100755 index ece4bfef1..000000000 --- a/ci/check_examples.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -echo "$(rustup default)" | grep -q "1.39.0" -emscripten_supported=$? -set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ - -# Some examples are known not to work with some builds, i.e. futures with the -# std_web feature. Other items in the examples/ directory are helpers, i.e. -# pub_sub and server. These block lists allow us to exempt some examples but -# default opt-in any new examples to CI testing. -COMMON_SKIP_EXAMPLES="examples/static examples/pub_sub examples/server \ - examples/target examples/web_sys examples/std_web" -STD_WEB_SKIP_EXAMPLES="${COMMON_SKIP_EXAMPLES:?} examples/futures" -WEB_SYS_SKIP_EXAMPLES="${COMMON_SKIP_EXAMPLES:?}" - -# Make sure all examples are buildable with stdweb and web-sys. -for ex in $(find examples -maxdepth 1 -mindepth 1 -type d); do - pushd $ex - - # TODO Can't build some demos with release, need fix - - if [ "$emscripten_supported" == "0" ]; then - if [[ ! " ${STD_WEB_SKIP_EXAMPLES[@]} " =~ " ${ex} " ]]; then - # TODO - Emscripten builds are broken on rustc > 1.39.0 - cargo web build --target asmjs-unknown-emscripten --features std_web - cargo web build --target wasm32-unknown-emscripten --features std_web - fi - fi - - if [[ ! " ${STD_WEB_SKIP_EXAMPLES[@]} " =~ " ${ex} " ]]; then - cargo web build --target wasm32-unknown-unknown --features std_web - fi - if [[ ! " ${WEB_SYS_SKIP_EXAMPLES[@]} " =~ " ${ex} " ]]; then - cargo build --target wasm32-unknown-unknown --features web_sys - fi - - # Reset cwd - popd -done diff --git a/ci/run_checks.sh b/ci/run_checks.sh deleted file mode 100755 index c57a67dd3..000000000 --- a/ci/run_checks.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -echo "$(rustup default)" | grep -q "stable" -if [ "$?" != "0" ]; then - # only run checks on stable - exit 0 -fi - -set -euxo pipefail -cargo fmt --all -- --check -cargo clippy --features std_web -- --deny=warnings -cargo clippy --features web_sys -- --deny=warnings diff --git a/ci/run_emscripten_checks.sh b/ci/run_emscripten_checks.sh new file mode 100755 index 000000000..b4d896bb4 --- /dev/null +++ b/ci/run_emscripten_checks.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +echo "$(rustup default)" | grep -q "1.39.0" +emscripten_supported=$? +set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ + +pushd yew-stdweb +if [ "$emscripten_supported" == "0" ]; then + # TODO - Emscripten builds are broken on rustc > 1.39.0 + cargo check --all --target asmjs-unknown-emscripten + cargo check --all --target wasm32-unknown-emscripten +fi +popd diff --git a/ci/run_stable_checks.sh b/ci/run_stable_checks.sh new file mode 100755 index 000000000..a85635b41 --- /dev/null +++ b/ci/run_stable_checks.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +echo "$(rustup default)" | grep -q "stable" +if [ "$?" != "0" ]; then + # only run checks on stable + exit 0 +fi + +set -euxo pipefail + +cargo fmt --all -- --check +cargo clippy --all -- --deny=warnings +cargo check --all + +# Enable all optional features +(cd yew \ + && cargo check --features cbor,msgpack,toml,yaml \ + && cargo clippy --features cbor,msgpack,toml,yaml -- --deny=warnings) + +# Check stdweb +pushd yew-stdweb +cargo fmt --all -- --check +cargo clippy --all -- --deny=warnings +cargo check --all --target wasm32-unknown-unknown + +# webgl_stdweb doesn't play nice with wasm-bindgen +(cd examples/webgl && cargo web check --target wasm32-unknown-unknown) +popd \ No newline at end of file diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 9819be55c..28a576e87 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -3,22 +3,25 @@ echo "$(rustup default)" | grep -q "1.39.0" emscripten_supported=$? set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ -cargo test --target wasm32-unknown-unknown --features wasm_test,std_web -cargo test --target wasm32-unknown-unknown --features wasm_test,web_sys +(cd yew \ + && cargo test --target wasm32-unknown-unknown --features wasm_test \ + && cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \ + && cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \ + --features std_web,agent,services --no-default-features) -if [ "$emscripten_supported" == "0" ]; then - # TODO - Emscripten builds are broken on rustc > 1.39.0 - cargo web test --target asmjs-unknown-emscripten --features std_web - cargo web test --target wasm32-unknown-emscripten --features std_web -fi +(cd yew-functional \ + && cargo test --target wasm32-unknown-unknown) -cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,std_web -cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,web_sys - -(cd crates/macro \ +(cd yew-macro \ && cargo test --test macro_test \ && cargo test --test derive_props_test \ && cargo test --doc) -(cd crates/functional \ - && cargo test --features wasm_test --target wasm32-unknown-unknown) +(cd yew-stdweb && cargo test --target wasm32-unknown-unknown --features wasm_test) + +# TODO - Emscripten builds are broken on rustc > 1.39.0 +if [ "$emscripten_supported" == "0" ]; then + (cd yew-stdweb \ + && cargo web test --target asmjs-unknown-emscripten \ + && cargo web test --target wasm32-unknown-emscripten) +fi diff --git a/crates/functional/tests/lib.rs b/crates/functional/tests/lib.rs deleted file mode 100644 index f2cc419fe..000000000 --- a/crates/functional/tests/lib.rs +++ /dev/null @@ -1,375 +0,0 @@ -#[cfg(test)] -extern crate wasm_bindgen_test; - -#[cfg(test)] -#[cfg(feature = "wasm_test")] -mod test { - use std::ops::Deref; - use std::ops::DerefMut; - use std::rc::Rc; - use wasm_bindgen_test::*; - wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); - - extern crate yew; - - use self::yew::NodeRef; - use yew::{html, App, Html, Properties}; - use yew_functional::{ - use_effect, use_effect_with_deps, use_reducer_with_init, use_ref, use_state, - FunctionComponent, FunctionProvider, - }; - - #[wasm_bindgen_test] - fn use_state_works() { - struct UseStateFunction {} - impl FunctionProvider for UseStateFunction { - type TProps = (); - - fn run(_: &Self::TProps) -> Html { - let (counter, set_counter) = use_state(|| 0); - if *counter < 5 { - set_counter(*counter + 1) - } - return html! { -
- {"Test Output: "} -
{*counter}
- {"\n"} -
- }; - } - } - type UseComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - let result = obtain_result(); - assert_eq!(result.as_str(), "5"); - } - - #[wasm_bindgen_test] - fn props_are_passed() { - struct PropsPassedFunction {} - #[derive(Properties, Clone, PartialEq)] - struct PropsPassedFunctionProps { - value: String, - } - impl FunctionProvider for PropsPassedFunction { - type TProps = PropsPassedFunctionProps; - - fn run(props: &Self::TProps) -> Html { - assert_eq!(&props.value, "props"); - return html! { -
- {"done"} -
- }; - } - } - type PropsComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount_with_props( - yew::utils::document().get_element_by_id("output").unwrap(), - PropsPassedFunctionProps { - value: "props".to_string(), - }, - ); - let result = obtain_result(); - assert_eq!(result.as_str(), "done"); - } - - #[wasm_bindgen_test] - fn use_ref_works() { - struct UseRefFunction {} - impl FunctionProvider for UseRefFunction { - type TProps = (); - - fn run(_: &Self::TProps) -> Html { - let ref_example = use_ref(|| 0); - *ref_example.borrow_mut().deref_mut() += 1; - let (counter, set_counter) = use_state(|| 0); - if *counter < 5 { - set_counter(*counter + 1) - } - return html! { -
- {"The test output is: "} -
{*ref_example.borrow_mut().deref_mut() > 4}
- {"\n"} -
- }; - } - } - type UseRefComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - - let result = obtain_result(); - assert_eq!(result.as_str(), "true"); - } - - #[wasm_bindgen_test] - fn use_reducer_works() { - struct UseReducerFunction {} - impl FunctionProvider for UseReducerFunction { - type TProps = (); - fn run(_: &Self::TProps) -> Html { - struct CounterState { - counter: i32, - } - let (counter, dispatch) = use_reducer_with_init( - |prev: std::rc::Rc, action: i32| CounterState { - counter: prev.counter + action, - }, - 0, - |initial: i32| CounterState { - counter: initial + 10, - }, - ); - - use_effect_with_deps( - move |_| { - dispatch(1); - || {} - }, - (), - ); - return html! { -
- {"The test result is"} -
{counter.counter}
- {"\n"} -
- }; - } - } - type UseReducerComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - let result = obtain_result(); - - assert_eq!(result.as_str(), "11"); - } - - #[wasm_bindgen_test] - fn use_effect_destroys_on_component_drop() { - struct UseEffectFunction {} - struct UseEffectWrapper {} - #[derive(Properties, Clone)] - struct DestroyCalledProps { - destroy_called: Rc, - } - impl PartialEq for DestroyCalledProps { - fn eq(&self, _other: &Self) -> bool { - false - } - } - type UseEffectComponent = FunctionComponent; - type UseEffectWrapperComponent = FunctionComponent; - impl FunctionProvider for UseEffectFunction { - type TProps = DestroyCalledProps; - - fn run(props: &Self::TProps) -> Html { - let destroy_called = props.destroy_called.clone(); - use_effect_with_deps( - move |_| { - move || { - destroy_called(); - } - }, - (), - ); - return html! {}; - } - } - impl FunctionProvider for UseEffectWrapper { - type TProps = DestroyCalledProps; - - fn run(props: &Self::TProps) -> Html { - let (should_rerender, set_rerender) = use_state(|| true); - if *should_rerender { - set_rerender(false); - return html! { - - }; - } else { - return html! { -
{"EMPTY"}
- }; - } - } - } - let app: App = yew::App::new(); - let destroy_counter = Rc::new(std::cell::RefCell::new(0)); - let destroy_country_c = destroy_counter.clone(); - app.mount_with_props( - yew::utils::document().get_element_by_id("output").unwrap(), - DestroyCalledProps { - destroy_called: Rc::new(move || *destroy_country_c.borrow_mut().deref_mut() += 1), - }, - ); - assert_eq!(1, *destroy_counter.borrow().deref()); - } - - #[wasm_bindgen_test] - fn use_effect_works_many_times() { - struct UseEffectFunction {} - impl FunctionProvider for UseEffectFunction { - type TProps = (); - - fn run(_: &Self::TProps) -> Html { - let (counter, set_counter) = use_state(|| 0); - if *counter < 4 { - set_counter(*counter + 1); - } - - let node_ref = NodeRef::default(); - let node_ref_c = node_ref.clone(); - - use_effect(move || { - let text_content = node_ref - .get() - .expect("Should have filled node_ref at this point") - .text_content() - .expect("Text node should have content"); - let mut previous = -1; - if *counter == 0 { - assert_eq!("placeholder that should not appear", &text_content); - } else { - previous = text_content - .parse() - .expect("Expected content to be number set last time"); - } - assert_eq!(previous, *counter - 1); - node_ref - .get() - .unwrap() - .set_text_content(Some(&format!("{}", counter))); - || {} - }); - - return html! { -
- {"The test result is"} -
{"placeholder that should not appear"}
- {"\n"} -
- }; - } - } - - type UseEffectComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - let result = obtain_result(); - assert_eq!(result.as_str(), "4"); - } - - #[wasm_bindgen_test] - fn use_effect_works_once() { - struct UseEffectFunction {} - impl FunctionProvider for UseEffectFunction { - type TProps = (); - - fn run(_: &Self::TProps) -> Html { - let number_ref = use_ref(|| 0); - let number_ref_c = number_ref.clone(); - let initially_true_ref = use_ref(|| false); - let initially_true_ref_c = initially_true_ref.clone(); - - let node_ref = NodeRef::default(); - let node_ref_c = node_ref.clone(); - - use_effect_with_deps( - move |_| { - if *initially_true_ref.borrow() { - panic!("use_effect should have been called post render!") - } - if *number_ref_c.borrow_mut().deref_mut() == 1 { - panic!("This effect should have been called once only") - } - *number_ref_c.borrow_mut().deref_mut() += 1; - node_ref - .get() - .expect("This NodeRef should point at the result!"); - || panic!("Destructor should not have been called") - }, - (), - ); - *initially_true_ref_c.borrow_mut() = false; - - let (do_rerender, set_rerender) = use_state(|| true); - if *do_rerender { - set_rerender(false); - } - - return html! { -
- {"The test result is"} -
{*number_ref.borrow_mut().deref_mut()}
- {"\n"} -
- }; - } - } - type UseEffectComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - let result = obtain_result(); - assert_eq!(result.as_str(), "1"); - } - - #[wasm_bindgen_test] - fn use_effect_refires_on_dependency_change() { - struct UseEffectFunction {} - impl FunctionProvider for UseEffectFunction { - type TProps = (); - - fn run(_: &Self::TProps) -> Html { - let number_ref = use_ref(|| 0); - let number_ref_c = number_ref.clone(); - let number_ref2 = use_ref(|| 0); - let number_ref2_c = number_ref2.clone(); - let arg = *number_ref.borrow_mut().deref_mut(); - let (_, set_counter) = use_state(|| 0); - use_effect_with_deps( - move |dep| { - let mut ref_mut = number_ref_c.borrow_mut(); - let inner_ref_mut = ref_mut.deref_mut(); - if *inner_ref_mut < 1 { - *inner_ref_mut += 1; - assert_eq!(dep, &0); - } else { - assert_eq!(dep, &1); - } - set_counter(10); // we just need to make sure it does not panic - move || { - set_counter(11); - *number_ref2_c.borrow_mut().deref_mut() += 1; - } - }, - arg, - ); - return html! { -
- {"The test result is"} -
{*number_ref.borrow_mut().deref_mut()}{*number_ref2.borrow_mut().deref_mut()}
- {"\n"} -
- }; - } - } - type UseEffectComponent = FunctionComponent; - let app: App = yew::App::new(); - app.mount(yew::utils::document().get_element_by_id("output").unwrap()); - let result: String = obtain_result(); - - assert_eq!(result.as_str(), "11"); - } - - fn obtain_result() -> String { - return yew::utils::document() - .get_element_by_id("result") - .expect("No result found. Most likely, the application crashed and burned") - .inner_html(); - } -} diff --git a/examples/Cargo.toml b/examples/Cargo.toml deleted file mode 100644 index 74f08f868..000000000 --- a/examples/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[workspace] -members = [ - "crm", - "custom_components", - "dashboard", - "fragments", - "futures", - "game_of_life", - "large_table", - "minimal", - "nested_list", - "pub_sub", - "server", - "showcase", - "textarea", - "timer", - "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", - "std_web/webgl", - "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", - "web_sys/webgl", -] diff --git a/examples/build_all.sh b/examples/build_all.sh deleted file mode 100755 index 15696561f..000000000 --- a/examples/build_all.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env bash - -PID=-1 - -function ctrl_c() { - echo "** Killing the demo..." - kill $PID -} - -function build_std_web() { - for example in */ ; do - if [[ $example == server* ]]; then - continue - fi - if [[ $example == static* ]]; then - 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_std_web() { - trap ctrl_c INT - for example in */ ; do - if [[ $example == server* ]]; then - continue - fi - 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 -} - -function clean() { - trap ctrl_c INT - for example in */ ; do - echo "Cleaning: $example" - cd $example - cargo clean - PID=$! - wait $PID - cd .. - done -} - -case "$1" in - --help) - echo "Available commands: build, run, clean" - ;; - build_std_web) - build_std_web - ;; - build_web_sys) - build_web_sys - ;; - run_std_web) - run_std_web - ;; - run_web_sys) - run_web_sys - ;; - clean) - clean - ;; -esac diff --git a/examples/web_sys/counter/Cargo.toml b/examples/counter/Cargo.toml similarity index 65% rename from examples/web_sys/counter/Cargo.toml rename to examples/counter/Cargo.toml index 71103f618..7a067fe29 100644 --- a/examples/web_sys/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "counter_web_sys" +name = "counter" version = "0.1.1" authors = ["Denis Kolodin "] edition = "2018" @@ -9,4 +9,4 @@ crate-type = ["cdylib", "rlib"] [dependencies] js-sys = "0.3" -yew = { path = "../../..", features = ["services", "web_sys"] } +yew = { path = "../../yew" } diff --git a/examples/web_sys/counter/src/lib.rs b/examples/counter/src/lib.rs similarity index 95% rename from examples/web_sys/counter/src/lib.rs rename to examples/counter/src/lib.rs index eb7953481..150f8cc95 100644 --- a/examples/web_sys/counter/src/lib.rs +++ b/examples/counter/src/lib.rs @@ -31,11 +31,11 @@ impl Component for Model { fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Increment => { - self.value = self.value + 1; + self.value += 1; self.console.log("plus one"); } Msg::Decrement => { - self.value = self.value - 1; + self.value -= 1; self.console.log("minus one"); } Msg::Bulk(list) => { diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs new file mode 100644 index 000000000..fa550b8b3 --- /dev/null +++ b/examples/counter/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + yew::start_app::(); +} diff --git a/examples/crm/Cargo.toml b/examples/crm/Cargo.toml index 248a56c92..b92521dd6 100644 --- a/examples/crm/Cargo.toml +++ b/examples/crm/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = "1" serde_derive = "1" -yew = { path = "../.." } +yew = { path = "../../yew" } pulldown-cmark = "0.1.2" [features] diff --git a/examples/crm/src/lib.rs b/examples/crm/src/lib.rs index 10ae866a1..8c9389da7 100644 --- a/examples/crm/src/lib.rs +++ b/examples/crm/src/lib.rs @@ -10,7 +10,7 @@ use yew::services::storage::Area; use yew::services::{DialogService, StorageService}; use yew::{html, Component, ComponentLink, Html, InputData, Renderable, ShouldRender}; -const KEY: &'static str = "yew.crm.database"; +const KEY: &str = "yew.crm.database"; #[derive(Serialize, Deserialize)] struct Database { diff --git a/examples/crm/src/markdown.rs b/examples/crm/src/markdown.rs index 9509303cb..f35e2fb8f 100644 --- a/examples/crm/src/markdown.rs +++ b/examples/crm/src/markdown.rs @@ -34,9 +34,9 @@ pub fn render_markdown(src: &str) -> Html { top = pre; } else if let Tag::Table(aligns) = tag { for r in top.children.iter_mut() { - if let &mut VNode::VTag(ref mut vtag) = r { + if let VNode::VTag(ref mut vtag) = r { for (i, c) in vtag.children.iter_mut().enumerate() { - if let &mut VNode::VTag(ref mut vtag) = c { + if let VNode::VTag(ref mut vtag) = c { match aligns[i] { Alignment::None => {} Alignment::Left => vtag.add_class("text-left"), @@ -49,7 +49,7 @@ pub fn render_markdown(src: &str) -> Html { } } else if let Tag::TableHead = tag { for c in top.children.iter_mut() { - if let &mut VNode::VTag(ref mut vtag) = c { + if let VNode::VTag(ref mut vtag) = c { // TODO // vtag.tag = "th".into(); vtag.add_attribute("scope", &"col"); diff --git a/examples/custom_components/Cargo.toml b/examples/custom_components/Cargo.toml index 9c8843fc8..1a34996fe 100644 --- a/examples/custom_components/Cargo.toml +++ b/examples/custom_components/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Denis Kolodin "] edition = "2018" [dependencies] -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["yew/std_web"] diff --git a/examples/custom_components/src/counter.rs b/examples/custom_components/src/counter.rs index aefdfbdc3..1c00d3a3d 100644 --- a/examples/custom_components/src/counter.rs +++ b/examples/custom_components/src/counter.rs @@ -43,7 +43,7 @@ impl Component for Counter { fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Increase => { - self.value = self.value + 1; + self.value += 1; self.onclick.emit(self.value); } } diff --git a/examples/dashboard/Cargo.toml b/examples/dashboard/Cargo.toml index 88d57d1f4..e6d7b5780 100644 --- a/examples/dashboard/Cargo.toml +++ b/examples/dashboard/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" anyhow = "1" serde = "1" serde_derive = "1" -yew = { path = "../..", features = ["toml"] } +yew = { path = "../../yew", features = ["toml"] } [features] std_web = ["yew/std_web"] diff --git a/examples/web_sys/file_upload/Cargo.toml b/examples/file_upload/Cargo.toml similarity index 67% rename from examples/web_sys/file_upload/Cargo.toml rename to examples/file_upload/Cargo.toml index 20007f519..f1824736b 100644 --- a/examples/web_sys/file_upload/Cargo.toml +++ b/examples/file_upload/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "file_upload_web_sys" +name = "file_upload" version = "0.1.0" authors = ["Denis Kolodin "] edition = "2018" @@ -9,4 +9,4 @@ crate-type = ["cdylib", "rlib"] [dependencies] js-sys = "0.3" -yew = { path = "../../..", features = ["web_sys"] } +yew = { path = "../../yew" } diff --git a/examples/web_sys/file_upload/src/lib.rs b/examples/file_upload/src/lib.rs similarity index 96% rename from examples/web_sys/file_upload/src/lib.rs rename to examples/file_upload/src/lib.rs index ca24c52fc..8a36d2286 100644 --- a/examples/web_sys/file_upload/src/lib.rs +++ b/examples/file_upload/src/lib.rs @@ -15,7 +15,7 @@ type Chunks = bool; pub enum Msg { Loaded(FileData), - Chunk(FileChunk), + Chunk(Option), Files(Vec, Chunks), ToggleByChunks, } @@ -40,7 +40,7 @@ impl Component for Model { let info = format!("file: {:?}", file); self.files.push(info); } - Msg::Chunk(chunk) => { + Msg::Chunk(Some(chunk)) => { let info = format!("chunk: {:?}", chunk); self.files.push(info); } @@ -61,6 +61,7 @@ impl Component for Model { Msg::ToggleByChunks => { self.by_chunks = !self.by_chunks; } + _ => return false, } true } diff --git a/examples/file_upload/src/main.rs b/examples/file_upload/src/main.rs new file mode 100644 index 000000000..405b92411 --- /dev/null +++ b/examples/file_upload/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + yew::start_app::(); +} diff --git a/examples/fragments/Cargo.toml b/examples/fragments/Cargo.toml index 5b4bceb71..11b2a160f 100644 --- a/examples/fragments/Cargo.toml +++ b/examples/fragments/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Denis Kolodin "] edition = "2018" [dependencies] -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["yew/std_web"] diff --git a/examples/fragments/src/lib.rs b/examples/fragments/src/lib.rs index 9a6e01642..4bb9ac244 100644 --- a/examples/fragments/src/lib.rs +++ b/examples/fragments/src/lib.rs @@ -23,11 +23,11 @@ impl Component for Model { fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::More => { - self.counter = self.counter + 1; + self.counter += 1; } Msg::Less => { if self.counter > 0 { - self.counter = self.counter - 1; + self.counter -= 1; } } } diff --git a/examples/futures/Cargo.toml b/examples/futures/Cargo.toml index 3637520d8..414a9b164 100644 --- a/examples/futures/Cargo.toml +++ b/examples/futures/Cargo.toml @@ -11,7 +11,8 @@ repository = "https://github.com/yewstack/yew" crate-type = ["cdylib", "rlib"] [dependencies] -yew = { path = "../.." } +yew = { path = "../../yew" } +wasm-bindgen = "0.2.60" wasm-bindgen-futures = "0.4.3" [dependencies.web-sys] @@ -24,10 +25,3 @@ features = [ 'Response', 'Window', ] - -[target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'.dependencies] -wasm-bindgen = "0.2.60" - -[features] -std_web = ["yew/std_web"] -web_sys = ["yew/web_sys"] diff --git a/examples/futures/README.md b/examples/futures/README.md index 9e5c9549e..0c1ef2c23 100644 --- a/examples/futures/README.md +++ b/examples/futures/README.md @@ -1,13 +1,11 @@ # Futures Example This example shows off how to make a asynchronous fetch request using web_sys and Yew's futures support. -Because this example uses features not allowed by cargo web, it cannot be included in the showcase, and must be built with a different toolchain instead. - ### How to run: 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 --out-dir ../static/ --out-name wasm -- --features (web_sys|std_web) && python -m SimpleHTTPServer 8080 +wasm-pack build --target web --out-dir ../static/ --out-name wasm && 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. diff --git a/examples/futures/src/lib.rs b/examples/futures/src/lib.rs index fd769305d..33db83408 100644 --- a/examples/futures/src/lib.rs +++ b/examples/futures/src/lib.rs @@ -3,29 +3,23 @@ use std::fmt::{Error, Formatter}; use std::future::Future; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; +use wasm_bindgen_futures::spawn_local; use wasm_bindgen_futures::JsFuture; use web_sys::{Request, RequestInit, RequestMode, Response, Window}; use yew::{html, Component, ComponentLink, Html, ShouldRender}; -#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), not(cargo_web)))] /// This method processes a Future that returns a message and sends it back to the component's /// loop. /// /// # Panics /// If the future panics, then the promise will not resolve, and will leak. -pub fn send_future(link: &ComponentLink, future: F) +pub fn send_future(link: ComponentLink, future: F) where F: Future + 'static, { - use wasm_bindgen_futures::future_to_promise; - - let mut link = link.clone(); - let js_future = async move { + spawn_local(async move { link.send_message(future.await); - Ok(JsValue::NULL) - }; - - future_to_promise(js_future); + }); } /// Something wrong has occurred while fetching an external resource. @@ -118,7 +112,7 @@ impl Component for Model { Err(err) => Msg::SetMarkdownFetchState(FetchState::Failed(err)), } }; - send_future(&self.link, future); + send_future(self.link.clone(), future); self.link .send_message(SetMarkdownFetchState(FetchState::Fetching)); false diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index a67d8ed4d..67326e960 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" rand = "0.6.5" log = "0.4" web_logger = "0.2" -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["rand/stdweb", "yew/std_web"] diff --git a/examples/game_of_life/src/lib.rs b/examples/game_of_life/src/lib.rs index 61c74cbfc..5a8a6fb24 100644 --- a/examples/game_of_life/src/lib.rs +++ b/examples/game_of_life/src/lib.rs @@ -36,7 +36,7 @@ impl Cellule { self.life_state = LifeState::Dead; } - pub fn alive(&self) -> bool { + pub fn alive(self) -> bool { self.life_state == LifeState::Alive } @@ -97,10 +97,8 @@ impl Model { if Cellule::alone(&neighbors) || Cellule::overpopulated(&neighbors) { to_dead.push(current_idx); } - } else { - if Cellule::can_be_revived(&neighbors) { - to_live.push(current_idx); - } + } else if Cellule::can_be_revived(&neighbors) { + to_live.push(current_idx); } } } diff --git a/examples/game_of_life/static/index.html b/examples/game_of_life/static/index.html index 9e38b56c9..741ea16d3 100644 --- a/examples/game_of_life/static/index.html +++ b/examples/game_of_life/static/index.html @@ -10,4 +10,3 @@ - diff --git a/examples/inner_html/Cargo.toml b/examples/inner_html/Cargo.toml new file mode 100644 index 000000000..c6ca1e6b6 --- /dev/null +++ b/examples/inner_html/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "inner_html" +version = "0.1.0" +authors = ["Garrett Berg "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +yew = { path = "../../yew" } + +[dependencies.web-sys] +version = "0.3" +features = [ + "console", + "Document", + "Element", + "Node", + "Window", +] diff --git a/examples/web_sys/inner_html/src/lib.rs b/examples/inner_html/src/lib.rs similarity index 100% rename from examples/web_sys/inner_html/src/lib.rs rename to examples/inner_html/src/lib.rs diff --git a/examples/std_web/inner_html/src/main.rs b/examples/inner_html/src/main.rs similarity index 100% rename from examples/std_web/inner_html/src/main.rs rename to examples/inner_html/src/main.rs diff --git a/examples/web_sys/js_callback/Cargo.toml b/examples/js_callback/Cargo.toml similarity index 53% rename from examples/web_sys/js_callback/Cargo.toml rename to examples/js_callback/Cargo.toml index fec057025..4803f4676 100644 --- a/examples/web_sys/js_callback/Cargo.toml +++ b/examples/js_callback/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "js_callback_web_sys" +name = "js_callback" version = "0.1.0" authors = ["Scott Steele "] edition = "2018" @@ -8,7 +8,5 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -yew = { path = "../../..", features = ["web_sys"] } - -[target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.60" +yew = { path = "../../yew" } diff --git a/examples/std_web/js_callback/README.md b/examples/js_callback/README.md similarity index 100% rename from examples/std_web/js_callback/README.md rename to examples/js_callback/README.md diff --git a/examples/web_sys/js_callback/src/lib.rs b/examples/js_callback/src/lib.rs similarity index 100% rename from examples/web_sys/js_callback/src/lib.rs rename to examples/js_callback/src/lib.rs diff --git a/examples/js_callback/src/main.rs b/examples/js_callback/src/main.rs new file mode 100644 index 000000000..b03f7331e --- /dev/null +++ b/examples/js_callback/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + yew::start_app::(); +} diff --git a/examples/std_web/js_callback/static/get-payload-script.js b/examples/js_callback/static/get-payload-script.js similarity index 100% rename from examples/std_web/js_callback/static/get-payload-script.js rename to examples/js_callback/static/get-payload-script.js diff --git a/examples/std_web/js_callback/static/index.html b/examples/js_callback/static/index.html similarity index 100% rename from examples/std_web/js_callback/static/index.html rename to examples/js_callback/static/index.html diff --git a/examples/large_table/Cargo.toml b/examples/large_table/Cargo.toml index b62c39ea0..d1c2de22c 100644 --- a/examples/large_table/Cargo.toml +++ b/examples/large_table/Cargo.toml @@ -5,7 +5,7 @@ authors = ["qthree "] edition = "2018" [dependencies] -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["yew/std_web"] diff --git a/examples/minimal/Cargo.toml b/examples/minimal/Cargo.toml index be969b88e..b88286989 100644 --- a/examples/minimal/Cargo.toml +++ b/examples/minimal/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Denis Kolodin "] edition = "2018" [dependencies] -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["yew/std_web"] diff --git a/examples/web_sys/mount_point/Cargo.toml b/examples/mount_point/Cargo.toml similarity index 80% rename from examples/web_sys/mount_point/Cargo.toml rename to examples/mount_point/Cargo.toml index a7146918e..d28c1c864 100644 --- a/examples/web_sys/mount_point/Cargo.toml +++ b/examples/mount_point/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mount_point_web_sys" +name = "mount_point" version = "0.1.0" authors = ["Ben Berman "] edition = "2018" @@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] wasm-bindgen = "0.2" -yew = { path = "../../..", features = ["web_sys"] } +yew = { path = "../../yew" } [dependencies.web-sys] version = "0.3" diff --git a/examples/std_web/mount_point/src/lib.rs b/examples/mount_point/src/lib.rs similarity index 100% rename from examples/std_web/mount_point/src/lib.rs rename to examples/mount_point/src/lib.rs diff --git a/examples/web_sys/mount_point/src/main.rs b/examples/mount_point/src/main.rs similarity index 96% rename from examples/web_sys/mount_point/src/main.rs rename to examples/mount_point/src/main.rs index 484d88d44..34dd2fa9c 100644 --- a/examples/web_sys/mount_point/src/main.rs +++ b/examples/mount_point/src/main.rs @@ -1,4 +1,4 @@ -use mount_point_web_sys::Model; +use mount_point::Model; use wasm_bindgen::JsValue; use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement}; use yew::App; diff --git a/examples/web_sys/multi_thread/Cargo.toml b/examples/multi_thread/Cargo.toml similarity index 77% rename from examples/web_sys/multi_thread/Cargo.toml rename to examples/multi_thread/Cargo.toml index 191566089..a4496fcf8 100644 --- a/examples/web_sys/multi_thread/Cargo.toml +++ b/examples/multi_thread/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "multi_thread_web_sys" +name = "multi_thread" version = "0.1.0" authors = ["Denis Kolodin "] edition = "2018" @@ -20,4 +20,4 @@ log = "0.4" wasm-logger = "0.2" serde = "1.0" serde_derive = "1.0" -yew = { path = "../../..", features = ["agent", "services", "web_sys"]} +yew = { path = "../../yew" } diff --git a/examples/web_sys/multi_thread/README.md b/examples/multi_thread/README.md similarity index 100% rename from examples/web_sys/multi_thread/README.md rename to examples/multi_thread/README.md diff --git a/examples/web_sys/multi_thread/src/bin/app.rs b/examples/multi_thread/src/bin/app.rs similarity index 56% rename from examples/web_sys/multi_thread/src/bin/app.rs rename to examples/multi_thread/src/bin/app.rs index 3cf99c96a..dc4d4c672 100644 --- a/examples/web_sys/multi_thread/src/bin/app.rs +++ b/examples/multi_thread/src/bin/app.rs @@ -1,4 +1,4 @@ fn main() { wasm_logger::init(wasm_logger::Config::default()); - yew::start_app::(); + yew::start_app::(); } diff --git a/examples/web_sys/multi_thread/src/bin/native_worker.rs b/examples/multi_thread/src/bin/native_worker.rs similarity index 61% rename from examples/web_sys/multi_thread/src/bin/native_worker.rs rename to examples/multi_thread/src/bin/native_worker.rs index f1cce19d0..6c90c2f9e 100644 --- a/examples/web_sys/multi_thread/src/bin/native_worker.rs +++ b/examples/multi_thread/src/bin/native_worker.rs @@ -2,5 +2,5 @@ use yew::agent::Threaded; fn main() { wasm_logger::init(wasm_logger::Config::default()); - multi_thread_web_sys::native_worker::Worker::register(); + multi_thread::native_worker::Worker::register(); } diff --git a/examples/web_sys/multi_thread/src/context.rs b/examples/multi_thread/src/context.rs similarity index 100% rename from examples/web_sys/multi_thread/src/context.rs rename to examples/multi_thread/src/context.rs diff --git a/examples/web_sys/multi_thread/src/job.rs b/examples/multi_thread/src/job.rs similarity index 100% rename from examples/web_sys/multi_thread/src/job.rs rename to examples/multi_thread/src/job.rs diff --git a/examples/web_sys/multi_thread/src/lib.rs b/examples/multi_thread/src/lib.rs similarity index 100% rename from examples/web_sys/multi_thread/src/lib.rs rename to examples/multi_thread/src/lib.rs diff --git a/examples/web_sys/multi_thread/src/native_worker.rs b/examples/multi_thread/src/native_worker.rs similarity index 100% rename from examples/web_sys/multi_thread/src/native_worker.rs rename to examples/multi_thread/src/native_worker.rs diff --git a/examples/web_sys/multi_thread/static/.gitignore b/examples/multi_thread/static/.gitignore similarity index 100% rename from examples/web_sys/multi_thread/static/.gitignore rename to examples/multi_thread/static/.gitignore diff --git a/examples/web_sys/multi_thread/static/index.html b/examples/multi_thread/static/index.html similarity index 99% rename from examples/web_sys/multi_thread/static/index.html rename to examples/multi_thread/static/index.html index 0a6ca751c..86775e39e 100644 --- a/examples/web_sys/multi_thread/static/index.html +++ b/examples/multi_thread/static/index.html @@ -7,4 +7,3 @@ - diff --git a/examples/nested_list/Cargo.toml b/examples/nested_list/Cargo.toml index 6dc090c35..8086f16a7 100644 --- a/examples/nested_list/Cargo.toml +++ b/examples/nested_list/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] log = "0.4" web_logger = "0.2" -yew = { path = "../.." } +yew = { path = "../../yew" } [features] std_web = ["yew/std_web"] diff --git a/examples/web_sys/node_refs/Cargo.toml b/examples/node_refs/Cargo.toml similarity index 75% rename from examples/web_sys/node_refs/Cargo.toml rename to examples/node_refs/Cargo.toml index dfae388ec..187147383 100644 --- a/examples/web_sys/node_refs/Cargo.toml +++ b/examples/node_refs/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "node_refs_web_sys" +name = "node_refs" version = "0.1.0" authors = ["Justin Starry "] edition = "2018" @@ -8,5 +8,5 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -yew = { path = "../../..", features = ["web_sys"] } +yew = { path = "../../yew" } web-sys = { version = "0.3", features = ["HtmlElement", "HtmlInputElement", "Node"] } diff --git a/examples/std_web/node_refs/src/input.rs b/examples/node_refs/src/input.rs similarity index 100% rename from examples/std_web/node_refs/src/input.rs rename to examples/node_refs/src/input.rs diff --git a/examples/web_sys/node_refs/src/lib.rs b/examples/node_refs/src/lib.rs similarity index 100% rename from examples/web_sys/node_refs/src/lib.rs rename to examples/node_refs/src/lib.rs diff --git a/examples/node_refs/src/main.rs b/examples/node_refs/src/main.rs new file mode 100644 index 000000000..63360e2c5 --- /dev/null +++ b/examples/node_refs/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + yew::start_app::(); +} diff --git a/examples/web_sys/npm_and_rest/Cargo.toml b/examples/npm_and_rest/Cargo.toml similarity index 77% rename from examples/web_sys/npm_and_rest/Cargo.toml rename to examples/npm_and_rest/Cargo.toml index 43ab59807..6c36ee506 100644 --- a/examples/web_sys/npm_and_rest/Cargo.toml +++ b/examples/npm_and_rest/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "npm_and_rest_web_sys" +name = "npm_and_rest" version = "0.1.0" authors = ["Denis Kolodin "] edition = "2018" @@ -14,4 +14,4 @@ serde = "1" serde_derive = "1" wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["console"] } -yew = { path = "../../..", features = ["web_sys"] } +yew = { path = "../../yew" } diff --git a/examples/web_sys/npm_and_rest/src/ccxt.rs b/examples/npm_and_rest/src/ccxt.rs similarity index 100% rename from examples/web_sys/npm_and_rest/src/ccxt.rs rename to examples/npm_and_rest/src/ccxt.rs diff --git a/examples/web_sys/npm_and_rest/src/gravatar.rs b/examples/npm_and_rest/src/gravatar.rs similarity index 100% rename from examples/web_sys/npm_and_rest/src/gravatar.rs rename to examples/npm_and_rest/src/gravatar.rs diff --git a/examples/web_sys/npm_and_rest/src/lib.rs b/examples/npm_and_rest/src/lib.rs similarity index 100% rename from examples/web_sys/npm_and_rest/src/lib.rs rename to examples/npm_and_rest/src/lib.rs diff --git a/examples/npm_and_rest/src/main.rs b/examples/npm_and_rest/src/main.rs new file mode 100644 index 000000000..8e3af40a3 --- /dev/null +++ b/examples/npm_and_rest/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + yew::start_app::(); +} diff --git a/examples/std_web/npm_and_rest/static/index.html b/examples/npm_and_rest/static/index.html similarity index 99% rename from examples/std_web/npm_and_rest/static/index.html rename to examples/npm_and_rest/static/index.html index a0e34651c..91c8c3688 100644 --- a/examples/std_web/npm_and_rest/static/index.html +++ b/examples/npm_and_rest/static/index.html @@ -9,4 +9,3 @@ - diff --git a/examples/old.Cargo.toml b/examples/old.Cargo.toml new file mode 100644 index 000000000..13a07b3d3 --- /dev/null +++ b/examples/old.Cargo.toml @@ -0,0 +1,26 @@ +[workspace] +members = [ + "counter", + "crm", + "custom_components", + "dashboard", + "file_upload", + "fragments", + "futures", + "game_of_life", + "inner_html", + "js_callback", + "large_table", + "minimal", + "mount_point", + "multi_thread", + "nested_list", + "node_refs", + "npm_and_rest", + "pub_sub", + "textarea", + "timer", + "todomvc", + "two_apps", + "webgl", +] diff --git a/examples/pub_sub/Cargo.toml b/examples/pub_sub/Cargo.toml index 058ebd133..fd919ed41 100644 --- a/examples/pub_sub/Cargo.toml +++ b/examples/pub_sub/Cargo.toml @@ -1,11 +1,14 @@ [package] -name = "event_bus" +name = "pub_sub" version = "0.1.0" edition = "2018" [dependencies] log = "0.4" -web_logger = "0.1" +web_logger = "0.2" serde = { version = "1.0", features = ["derive"] } -yew = { path = "../..", features = ["std_web"] } -stdweb = "0.4.20" +yew = { path = "../../yew" } + +[features] +std_web = ["yew/std_web"] +web_sys = ["yew/web_sys"] diff --git a/examples/pub_sub/src/main.rs b/examples/pub_sub/src/main.rs index ec6b79e99..56b74fe4f 100644 --- a/examples/pub_sub/src/main.rs +++ b/examples/pub_sub/src/main.rs @@ -1,3 +1,3 @@ fn main() { - yew::start_app::(); + yew::start_app::(); } diff --git a/examples/pub_sub/src/producer.rs b/examples/pub_sub/src/producer.rs index b50405e08..68e9689ed 100644 --- a/examples/pub_sub/src/producer.rs +++ b/examples/pub_sub/src/producer.rs @@ -24,15 +24,15 @@ impl Component for Producer { Producer { event_bus, link } } - fn change(&mut self, _: Self::Properties) -> bool { - false - } + fn change(&mut self, _: Self::Properties) -> bool { + false + } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Clicked => { self.event_bus - .send(Request::EventBusMsg(format!("Message received"))); + .send(Request::EventBusMsg("Message received".to_string())); false } } diff --git a/examples/pub_sub/src/subscriber.rs b/examples/pub_sub/src/subscriber.rs index 3759f10be..abe53a97d 100644 --- a/examples/pub_sub/src/subscriber.rs +++ b/examples/pub_sub/src/subscriber.rs @@ -16,10 +16,10 @@ impl Component for Subscriber { type Properties = (); fn create(_: Self::Properties, link: ComponentLink) -> Self { - let callback = link.callback(|s| Msg::NewMessage(s)); + let callback = link.callback(Msg::NewMessage); let _producer = EventBus::bridge(callback); Subscriber { - message: format!("No message yet."), + message: "No message yet.".to_string(), _producer, } } diff --git a/examples/showcase/Cargo.toml b/examples/showcase/Cargo.toml deleted file mode 100644 index eb6c311f2..000000000 --- a/examples/showcase/Cargo.toml +++ /dev/null @@ -1,73 +0,0 @@ -[package] -name = "showcase" -version = "0.1.0" -authors = ["Denis Kolodin ", "Limira"] -edition = "2018" - -[dependencies] -cfg-if = "0.1" -log = "0.4" -web_logger = "0.2" -strum = "0.13" -strum_macros = "0.13" -yew = { path = "../.." } -counter_std_web = { path = "../std_web/counter", optional = true } -counter_web_sys = { path = "../web_sys/counter", optional = true } -crm = { path = "../crm" } -custom_components = { path = "../custom_components" } -dashboard = { path = "../dashboard" } -node_refs_std_web = { path = "../std_web/node_refs", optional = true } -node_refs_web_sys = { path = "../web_sys/node_refs", optional = true } -fragments = { path = "../fragments" } -game_of_life = { path = "../game_of_life" } -inner_html_std_web = { path = "../std_web/inner_html", optional = true } -inner_html_web_sys = { path = "../web_sys/inner_html", optional = true } -large_table = { path = "../large_table" } -mount_point_std_web = { path = "../std_web/mount_point", optional = true } -mount_point_web_sys = { path = "../web_sys/mount_point", optional = true } -npm_and_rest_std_web = { path = "../std_web/npm_and_rest", optional = true } -npm_and_rest_web_sys = { path = "../web_sys/npm_and_rest", optional = true } -textarea = { path = "../textarea" } -timer = { path = "../timer" } -todomvc_std_web = { path = "../std_web/todomvc", optional = true } -todomvc_web_sys = { path = "../web_sys/todomvc", optional = true } -two_apps_std_web = { path = "../std_web/two_apps", optional = true } -two_apps_web_sys = { path = "../web_sys/two_apps", optional = true } - -[features] -std_web = [ - "yew/std_web", - "counter_std_web", - "crm/std_web", - "custom_components/std_web", - "dashboard/std_web", - "node_refs_std_web", - "fragments/std_web", - "game_of_life/std_web", - "inner_html_std_web", - "large_table/std_web", - "mount_point_std_web", - "npm_and_rest_std_web", - "textarea/std_web", - "timer/std_web", - "todomvc_std_web", - "two_apps_std_web", -] -web_sys = [ - "yew/web_sys", - "counter_web_sys", - "crm/web_sys", - "custom_components/web_sys", - "dashboard/web_sys", - "node_refs_web_sys", - "fragments/web_sys", - "game_of_life/web_sys", - "inner_html_web_sys", - "large_table/web_sys", - "mount_point_web_sys", - "npm_and_rest_web_sys", - "textarea/web_sys", - "timer/web_sys", - "todomvc_web_sys", - "two_apps_web_sys", -] diff --git a/examples/showcase/src/main.rs b/examples/showcase/src/main.rs deleted file mode 100644 index 835d28f9c..000000000 --- a/examples/showcase/src/main.rs +++ /dev/null @@ -1,171 +0,0 @@ -#![recursion_limit = "128"] - -cfg_if::cfg_if! { - if #[cfg(feature = "std_web")] { - use counter_std_web as counter; - use inner_html_std_web as inner_html; - use mount_point_std_web as mount_point; - use node_refs_std_web as node_refs; - use npm_and_rest_std_web as npm_and_rest; - use todomvc_std_web as todomvc; - use two_apps_std_web as two_apps; - } else if #[cfg(feature = "web_sys")] { - use counter_web_sys as counter; - use inner_html_web_sys as inner_html; - use mount_point_web_sys as mount_point; - use node_refs_web_sys as node_refs; - use npm_and_rest_web_sys as npm_and_rest; - use todomvc_web_sys as todomvc; - use two_apps_web_sys as two_apps; - } -} - -use counter::Model as Counter; -use crm::Model as Crm; -use custom_components::Model as CustomComponents; -use dashboard::Model as Dashboard; -use fragments::Model as Fragments; -use game_of_life::Model as GameOfLife; -use inner_html::Model as InnerHtml; -use large_table::Model as LargeTable; -use log::trace; -use mount_point::Model as MountPoint; -use node_refs::Model as NodeRefs; -use npm_and_rest::Model as NpmAndRest; -use strum::IntoEnumIterator; -use strum_macros::{Display, EnumIter, EnumString}; -use textarea::Model as Textarea; -use timer::Model as Timer; -use todomvc::Model as Todomvc; -use two_apps::TwoModels as TwoApps; -use yew::components::Select; -use yew::{html, App, Component, ComponentLink, Html, ShouldRender}; - -#[derive(Clone, Debug, Display, EnumString, EnumIter, PartialEq)] -enum Scene { - Counter, - Crm, - CustomComponents, - Dashboard, - NodeRefs, - Fragments, - GameOfLife, - InnerHtml, - LargeTable, - MountPoint, - NpmAndRest, - Textarea, - Timer, - Todomvc, - TwoApps, -} - -struct Model { - scene: Option, - link: ComponentLink, -} - -enum Msg { - SwitchTo(Scene), - Reset, -} - -impl Component for Model { - type Message = Msg; - type Properties = (); - - fn create(_: Self::Properties, link: ComponentLink) -> Self { - Self { scene: None, link } - } - - fn update(&mut self, msg: Self::Message) -> ShouldRender { - match msg { - Msg::SwitchTo(scene) => { - self.scene = Some(scene); - true - } - Msg::Reset => { - self.scene = None; - true - } - } - } - - fn change(&mut self, _: Self::Properties) -> ShouldRender { - false - } - - fn view(&self) -> Html { - html! { -
- -
-

{ "Yew showcase" }

- - selected=self.scene.clone() - options=Scene::iter().collect::>() - onchange=self.link.callback(Msg::SwitchTo) /> - -
-
- { self.view_scene() } -
-
- } - } -} - -impl Model { - fn view_scene(&self) -> Html { - if let Some(scene) = self.scene.as_ref() { - match scene { - Scene::Counter => html! { }, - Scene::Crm => html! { }, - Scene::CustomComponents => html! { }, - Scene::Dashboard => html! { }, - Scene::NodeRefs => html! { }, - Scene::Fragments => html! { }, - Scene::GameOfLife => html! { }, - Scene::InnerHtml => html! { }, - Scene::LargeTable => html! { }, - Scene::MountPoint => html! { }, - Scene::NpmAndRest => html! { }, - Scene::Textarea => html! {