├── yew ├── src │ ├── prelude.rs │ ├── format │ │ ├── toml.rs │ │ ├── yaml.rs │ │ ├── cbor.rs │ │ ├── bincode.rs │ │ ├── nothing.rs │ │ ├── msgpack.rs │ │ └── json.rs │ └── services │ │ ├── mod.rs │ │ ├── reader.rs │ │ └── dialog.rs └── build.rs ├── yew-stdweb ├── src └── examples │ ├── multi_thread │ ├── Web.toml │ ├── static │ │ ├── bin │ │ └── index.html │ ├── src │ │ ├── bin │ │ │ ├── main.rs │ │ │ └── native_worker.rs │ │ ├── job.rs │ │ ├── context.rs │ │ └── native_worker.rs │ ├── README.md │ └── Cargo.toml │ ├── counter │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml │ ├── todomvc │ ├── src │ │ └── main.rs │ ├── README.md │ ├── Cargo.toml │ └── static │ │ └── index.html │ ├── file_upload │ ├── src │ │ └── main.rs │ └── Cargo.toml │ ├── inner_html │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml │ ├── js_callback │ ├── src │ │ └── main.rs │ ├── static │ │ ├── get-payload-script.js │ │ └── index.html │ ├── README.md │ └── Cargo.toml │ ├── node_refs │ ├── src │ │ ├── main.rs │ │ └── input.rs │ └── Cargo.toml │ ├── npm_and_rest │ ├── src │ │ ├── main.rs │ │ ├── ccxt.rs │ │ └── gravatar.rs │ ├── static │ │ └── index.html │ └── Cargo.toml │ ├── webgl │ ├── src │ │ ├── main.rs │ │ ├── basic.vert │ │ └── basic.frag │ ├── README.md │ └── Cargo.toml │ ├── mount_point │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── lib.rs │ ├── two_apps │ ├── Cargo.toml │ ├── static │ │ └── index.html │ └── src │ │ └── main.rs │ └── README.md ├── yew-router ├── examples │ ├── static │ │ ├── .gitignore │ │ └── index.html │ ├── switch │ │ ├── README.md │ │ └── Cargo.toml │ ├── router_component │ │ ├── README.md │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── c_component.rs │ │ │ └── a_component.rs │ ├── servers │ │ ├── warp │ │ │ └── Cargo.toml │ │ ├── actix │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ └── Readme.md │ ├── minimal │ │ ├── Cargo.toml │ │ └── README.md │ └── README.md ├── src │ ├── agent │ │ ├── dispatcher.rs │ │ └── bridge.rs │ └── components │ │ ├── mod.rs │ │ └── router_button.rs └── Cargo.toml ├── examples ├── dashboard │ ├── static │ │ ├── data.toml │ │ └── data.json │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── multi_thread │ ├── static │ │ ├── .gitignore │ │ └── index.html │ ├── src │ │ ├── bin │ │ │ ├── app.rs │ │ │ └── native_worker.rs │ │ ├── job.rs │ │ ├── context.rs │ │ └── native_worker.rs │ ├── Cargo.toml │ └── README.md ├── crm │ ├── src │ │ └── main.rs │ ├── README.md │ └── Cargo.toml ├── static │ ├── .gitignore │ └── index.html ├── timer │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── webgl │ ├── src │ │ ├── main.rs │ │ ├── basic.vert │ │ └── basic.frag │ ├── README.md │ └── Cargo.toml ├── counter │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml ├── fragments │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── minimal │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml ├── node_refs │ ├── src │ │ ├── main.rs │ │ └── input.rs │ └── Cargo.toml ├── pub_sub │ ├── src │ │ ├── main.rs │ │ ├── lib.rs │ │ ├── subscriber.rs │ │ ├── event_bus.rs │ │ └── producer.rs │ ├── README.md │ └── Cargo.toml ├── textarea │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml ├── todomvc │ ├── src │ │ └── main.rs │ ├── README.md │ ├── Cargo.toml │ └── static │ │ └── index.html ├── file_upload │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── inner_html │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ └── Cargo.toml ├── js_callback │ ├── src │ │ └── main.rs │ ├── Cargo.toml │ ├── static │ │ ├── get-payload-script.js │ │ └── index.html │ └── README.md ├── large_table │ ├── src │ │ ├── main.rs │ │ └── lib.rs │ ├── Cargo.toml │ └── static │ │ ├── index.html │ │ └── styles.css ├── npm_and_rest │ ├── src │ │ ├── main.rs │ │ ├── ccxt.rs │ │ └── gravatar.rs │ ├── static │ │ └── index.html │ └── Cargo.toml ├── custom_components │ ├── src │ │ ├── main.rs │ │ ├── button.rs │ │ ├── barrier.rs │ │ ├── counter.rs │ │ └── lib.rs │ ├── Cargo.toml │ └── README.md ├── game_of_life │ ├── static │ │ ├── favicon.ico │ │ ├── index.html │ │ └── styles.css │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── nested_list │ ├── src │ │ ├── main.rs │ │ ├── lib.rs │ │ ├── header.rs │ │ └── item.rs │ ├── Cargo.toml │ └── static │ │ ├── index.html │ │ └── styles.css ├── server │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── two_apps │ ├── Cargo.toml │ ├── static │ │ └── index.html │ └── src │ │ └── main.rs ├── minimal_wp │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── mount_point │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── lib.rs ├── futures_wp │ ├── README.md │ └── Cargo.toml └── README.md ├── .gitignore ├── .cargo └── config ├── yewtil ├── examples │ ├── fetch │ │ ├── .cargo │ │ │ └── config │ │ ├── main.js │ │ ├── index.html │ │ ├── Readme.md │ │ └── Cargo.toml │ ├── futures │ │ ├── main.js │ │ ├── index.html │ │ ├── Cargo.toml │ │ └── README.md │ ├── effect │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── history │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── mrc_irc │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── child.rs │ │ │ └── main.rs │ ├── dsl │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── lrc │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── main.rs │ │ │ └── child.rs │ ├── pure_component │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── button.rs │ │ │ └── main.rs │ └── function_component │ │ ├── src │ │ ├── button.rs │ │ └── main.rs │ │ └── Cargo.toml ├── CHANGELOG.md ├── src │ ├── ptr │ │ ├── mod.rs │ │ └── takeable.rs │ ├── dsl │ │ ├── vtext.rs │ │ ├── vcomp.rs │ │ └── vlist.rs │ ├── lib.rs │ ├── not_equal_assign.rs │ ├── dsl.rs │ └── pure.rs └── Cargo.toml ├── yew-macro ├── tests │ ├── macro │ │ ├── html-component-fail-unimplemented.rs │ │ ├── html-list-pass.rs │ │ ├── html-block-fail.rs │ │ ├── html-list-fail.rs │ │ ├── html-iterable-fail.rs │ │ ├── html-iterable-pass.rs │ │ ├── html-node-pass.rs │ │ ├── html-node-fail.rs │ │ ├── test_component.rs │ │ ├── html-block-pass.rs │ │ ├── html-component-fail-unimplemented.stderr │ │ └── html-tag-fail.rs │ ├── derive_props_test.rs │ └── macro_test.rs ├── Cargo.toml └── src │ ├── html_tree │ ├── html_block.rs │ ├── html_iterable.rs │ └── html_node.rs │ └── derive_props │ └── wrapper.rs ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── ask-question.md │ ├── feature_request.md │ └── bug_report.md ├── FUNDING.yml └── ISSUE_TEMPLATE.md ├── yew-components ├── src │ └── lib.rs └── Cargo.toml ├── yewtil-macro ├── src │ └── lib.rs └── Cargo.toml ├── yew-router-route-parser └── Cargo.toml ├── .static └── yew.svg ├── ci ├── install_cargo_web.sh ├── run_stable_checks.sh ├── run_tests.sh ├── build_examples.sh └── clear_cache.sh ├── .mergify.yml ├── yew-router-macro ├── Cargo.toml └── src │ └── switch │ ├── enum_impl.rs │ ├── struct_impl.rs │ └── switch_impl.rs ├── yew-functional └── Cargo.toml ├── .travis.yml ├── LICENSE-MIT ├── Cargo.toml └── CONTRIBUTING.md /yew/src/prelude.rs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yew-stdweb/src: -------------------------------------------------------------------------------- 1 | ../yew/src -------------------------------------------------------------------------------- /yew-router/examples/static/.gitignore: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /examples/dashboard/static/data.toml: -------------------------------------------------------------------------------- 1 | value = 567 2 | -------------------------------------------------------------------------------- /examples/multi_thread/static/.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | *.wasm 3 | -------------------------------------------------------------------------------- /examples/dashboard/static/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "value": 123 3 | } 4 | -------------------------------------------------------------------------------- /examples/crm/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/Web.toml: -------------------------------------------------------------------------------- 1 | default-target = "wasm32-unknown-unknown" 2 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/static/bin: -------------------------------------------------------------------------------- 1 | ../../target/wasm32-unknown-unknown/release -------------------------------------------------------------------------------- /examples/static/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.js 3 | *.json 4 | *.ts 5 | *.md 6 | snippets/ 7 | -------------------------------------------------------------------------------- /examples/timer/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/webgl/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | **/*.rs.bk 3 | Cargo.lock 4 | orig.* 5 | /.idea 6 | /cmake-build-debug 7 | -------------------------------------------------------------------------------- /examples/counter/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/dashboard/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/fragments/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/minimal/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/node_refs/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/pub_sub/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/textarea/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/todomvc/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/file_upload/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/inner_html/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/js_callback/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/large_table/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /examples/npm_and_rest/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/counter/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/todomvc/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/file_upload/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/inner_html/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/js_callback/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/node_refs/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /.cargo/config: -------------------------------------------------------------------------------- 1 | [target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'] 2 | runner = 'wasm-bindgen-test-runner' 3 | -------------------------------------------------------------------------------- /examples/custom_components/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yew-stdweb/examples/npm_and_rest/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | yew::start_app::(); 3 | } 4 | -------------------------------------------------------------------------------- /yewtil/examples/fetch/.cargo/config: -------------------------------------------------------------------------------- 1 | # Allow cargo-check to work as expected. 2 | [build] 3 | target = "wasm32-unknown-unknown" 4 | -------------------------------------------------------------------------------- /examples/game_of_life/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdesjardins/yew/master/examples/game_of_life/static/favicon.ico -------------------------------------------------------------------------------- /yew-stdweb/examples/webgl/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | #[cfg(feature = "webgl_stdweb")] 3 | yew::start_app::(); 4 | } 5 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/src/bin/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | web_logger::init(); 3 | yew::start_app::(); 4 | } 5 | -------------------------------------------------------------------------------- /examples/nested_list/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | wasm_logger::init(wasm_logger::Config::default()); 3 | yew::start_app::(); 4 | } 5 | -------------------------------------------------------------------------------- /yew-router/examples/switch/README.md: -------------------------------------------------------------------------------- 1 | Run with `cargo run`. This example does not make use of web technologies and only demonstrates ways to construct URL matchers. -------------------------------------------------------------------------------- /examples/multi_thread/src/bin/app.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | wasm_logger::init(wasm_logger::Config::default()); 3 | yew::start_app::(); 4 | } 5 | -------------------------------------------------------------------------------- /examples/pub_sub/README.md: -------------------------------------------------------------------------------- 1 | ## Sender receiver example 2 | Basic example that show how components that are not aware of each other can communicate 3 | using an agent. 4 | -------------------------------------------------------------------------------- /examples/webgl/src/basic.vert: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | attribute vec2 a_position; 4 | 5 | void main() { 6 | gl_Position = vec4(a_position, 0.0, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /yewtil/examples/fetch/main.js: -------------------------------------------------------------------------------- 1 | import init, { run_app } from './pkg/fetch.js'; 2 | async function main() { 3 | await init('./pkg/fetch_bg.wasm'); 4 | run_app(); 5 | } 6 | main() -------------------------------------------------------------------------------- /yew-stdweb/examples/webgl/src/basic.vert: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | attribute vec2 a_position; 4 | 5 | void main() { 6 | gl_Position = vec4(a_position, 0.0, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /yewtil/examples/futures/main.js: -------------------------------------------------------------------------------- 1 | import init, { run_app } from './pkg/futures.js'; 2 | async function main() { 3 | await init('./pkg/futures_bg.wasm'); 4 | run_app(); 5 | } 6 | main() -------------------------------------------------------------------------------- /yew-stdweb/examples/webgl/README.md: -------------------------------------------------------------------------------- 1 | ## Yew WebGL Demo 2 | 3 | This is a simple demo using WebGL with Yew to initialize the GL context, create a render loop, and draw to the canvas with basic shaders. 4 | -------------------------------------------------------------------------------- /examples/server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "server" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | tungstenite = "0.10.1" 9 | -------------------------------------------------------------------------------- /examples/webgl/README.md: -------------------------------------------------------------------------------- 1 | ## Yew WebGL Demo 2 | 3 | This is a simple demo using WebGL with Yew to initialize the GL context, create 4 | a render loop, and draw to the canvas with basic shaders using `web-sys`. 5 | -------------------------------------------------------------------------------- /yew-router/examples/router_component/README.md: -------------------------------------------------------------------------------- 1 | # Router Component Example 2 | Run with `cargo web start`. 3 | 4 | Shows how to use the `Router` component. 5 | This is the preferred way of how to use this library. -------------------------------------------------------------------------------- /examples/large_table/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "large_table" 3 | version = "0.1.0" 4 | authors = ["qthree "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /examples/textarea/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "textarea" 3 | version = "0.1.0" 4 | authors = ["Andrew Straw "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /examples/timer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "timer" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-component-fail-unimplemented.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "128"] 2 | 3 | use yew::prelude::*; 4 | 5 | fn compile_fail() { 6 | html! { }; 7 | } 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /examples/fragments/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fragments" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /examples/multi_thread/src/bin/native_worker.rs: -------------------------------------------------------------------------------- 1 | use yew::agent::Threaded; 2 | 3 | fn main() { 4 | wasm_logger::init(wasm_logger::Config::default()); 5 | multi_thread::native_worker::Worker::register(); 6 | } 7 | -------------------------------------------------------------------------------- /examples/two_apps/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "two_apps" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/README.md: -------------------------------------------------------------------------------- 1 | ### multi_thread 2 | 3 | You should compile a worker which have to be spawned in a separate thread: 4 | 5 | ```sh 6 | cargo web build --bin native_worker --release 7 | ``` 8 | -------------------------------------------------------------------------------- /examples/crm/README.md: -------------------------------------------------------------------------------- 1 | ## Yew CRM Demo 2 | 3 | The main goals of this demo example to show you how to: 4 | 5 | * Add multiple screens with Yew (scenes) 6 | * Use storage service 7 | * Generate VNodes without the html! macro 8 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Reference: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 2 | 3 | yew-router/ @hgzimmerman 4 | yew-router-macro/ @hgzimmerman 5 | yew-router-route-parser/ @hgzimmerman -------------------------------------------------------------------------------- /examples/minimal/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "minimal" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | 10 | -------------------------------------------------------------------------------- /yew-components/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate contains useful Yew components. 2 | //! At this moment it only includes typed `Select`. 3 | 4 | #[doc(hidden)] 5 | pub mod select; 6 | 7 | #[doc(inline)] 8 | pub use self::select::Select; 9 | -------------------------------------------------------------------------------- /examples/custom_components/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "custom_components" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | -------------------------------------------------------------------------------- /examples/counter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "counter" 3 | version = "0.1.1" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | js-sys = "0.3" 9 | yew = { path = "../../yew" } 10 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/src/bin/native_worker.rs: -------------------------------------------------------------------------------- 1 | use yew::agent::Threaded; 2 | 3 | fn main() { 4 | web_logger::init(); 5 | yew::initialize(); 6 | multi_thread::native_worker::Worker::register(); 7 | yew::run_loop(); 8 | } 9 | -------------------------------------------------------------------------------- /yewtil/examples/fetch/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yewtil • Fetch 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /yewtil/examples/futures/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Futures 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/file_upload/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "file_upload" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | js-sys = "0.3" 9 | yew = { path = "../../yew" } 10 | -------------------------------------------------------------------------------- /examples/js_callback/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "js_callback" 3 | version = "0.1.0" 4 | authors = ["Scott Steele "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | wasm-bindgen = "0.2.60" 9 | yew = { path = "../../yew" } 10 | -------------------------------------------------------------------------------- /examples/js_callback/static/get-payload-script.js: -------------------------------------------------------------------------------- 1 | function get_payload() { 2 | return (new Date()).toString() 3 | } 4 | 5 | function get_payload_later(callback) { 6 | setTimeout(() => { 7 | callback(get_payload()) 8 | }, 1000) 9 | } 10 | -------------------------------------------------------------------------------- /examples/todomvc/README.md: -------------------------------------------------------------------------------- 1 | ## Yew TodoMVC Demo 2 | 3 | This is an implementation of [TodoMVC](http://todomvc.com/) app. 4 | 5 | Unlike other implementations, this stores the full state of the model, 6 | including: all entries, entered text and chosen filter. 7 | -------------------------------------------------------------------------------- /examples/pub_sub/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pub_sub" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | log = "0.4" 8 | wasm-logger = "0.2.0" 9 | serde = { version = "1.0", features = ["derive"] } 10 | yew = { path = "../../yew" } 11 | -------------------------------------------------------------------------------- /yew-macro/tests/derive_props_test.rs: -------------------------------------------------------------------------------- 1 | #[allow(dead_code)] 2 | #[rustversion::attr(stable(1.43), test)] 3 | fn tests() { 4 | let t = trybuild::TestCases::new(); 5 | t.pass("tests/derive_props/pass.rs"); 6 | t.compile_fail("tests/derive_props/fail.rs"); 7 | } 8 | -------------------------------------------------------------------------------- /yew-router/examples/switch/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "switch" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew-router = { path = "../..", default-features = false, features = ["web_sys"] } 9 | -------------------------------------------------------------------------------- /yew-stdweb/examples/js_callback/static/get-payload-script.js: -------------------------------------------------------------------------------- 1 | function get_payload() { 2 | return (new Date()).toString() 3 | } 4 | 5 | function get_payload_later(callback) { 6 | setTimeout(() => { 7 | callback(get_payload()) 8 | }, 1000) 9 | } 10 | -------------------------------------------------------------------------------- /yew-stdweb/examples/todomvc/README.md: -------------------------------------------------------------------------------- 1 | ## Yew TodoMVC Demo 2 | 3 | This it an implementationt of [TodoMVC](http://todomvc.com/) app. 4 | 5 | Unlike other implementations, this stores the full state of the model, 6 | including: all entries, entered text and chosen filter. 7 | -------------------------------------------------------------------------------- /examples/nested_list/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nested_list" 3 | version = "0.1.0" 4 | authors = ["Justin Starry "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | log = "0.4" 9 | wasm-logger = "0.2.0" 10 | yew = { path = "../../yew" } 11 | -------------------------------------------------------------------------------- /examples/webgl/src/basic.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform float u_time; 4 | 5 | void main() { 6 | float r = sin(u_time * 0.0003); 7 | float g = sin(u_time * 0.0005); 8 | float b = sin(u_time * 0.0007); 9 | 10 | gl_FragColor = vec4(r, g, b, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Multi-Thread 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/dashboard/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dashboard" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | anyhow = "1" 9 | serde = "1" 10 | serde_derive = "1" 11 | yew = { path = "../../yew", features = ["toml"] } 12 | -------------------------------------------------------------------------------- /yew-stdweb/examples/webgl/src/basic.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform float u_time; 4 | 5 | void main() { 6 | float r = sin(u_time * 0.0003); 7 | float g = sin(u_time * 0.0005); 8 | float b = sin(u_time * 0.0007); 9 | 10 | gl_FragColor = vec4(r, g, b, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /examples/multi_thread/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Multi-Thread 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/todomvc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todomvc" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | strum = "0.18" 9 | strum_macros = "0.18" 10 | serde = "1" 11 | serde_derive = "1" 12 | yew = { path = "../../yew" } 13 | -------------------------------------------------------------------------------- /examples/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew example 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/node_refs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "node_refs" 3 | version = "0.1.0" 4 | authors = ["Justin Starry "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | web-sys = { version = "0.3", features = ["HtmlElement", "HtmlInputElement", "Node"] } 10 | -------------------------------------------------------------------------------- /examples/crm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "crm" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | serde = "1" 9 | serde_derive = "1" 10 | yew = { path = "../../yew" } 11 | pulldown-cmark = { version = "0.7.0", default-features = false } 12 | -------------------------------------------------------------------------------- /examples/js_callback/README.md: -------------------------------------------------------------------------------- 1 | # (Asynchronous) callback from Javascript 2 | 3 | The purpose of this example is to demonstrate a simple case of asynchronously 4 | sending a message back into the component update loop. 5 | 6 | See for discussion on what 7 | motivated this example. 8 | -------------------------------------------------------------------------------- /yew-router/examples/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew example 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /yewtil/examples/effect/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "effect" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | log = "0.4.8" 9 | wasm-logger = "0.2.0" 10 | yew = { path = "../../../yew" } 11 | yewtil = { path = "../..", features = ["effect"] } 12 | -------------------------------------------------------------------------------- /yewtil/examples/history/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "history" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | 8 | [dependencies] 9 | log = "0.4.8" 10 | wasm-logger = "0.2.0" 11 | yew = { path = "../../../yew" } 12 | yewtil = { path = "../.." } 13 | -------------------------------------------------------------------------------- /yewtil/examples/mrc_irc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mrc_irc" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | 8 | [dependencies] 9 | log = "0.4.8" 10 | wasm-logger = "0.2.0" 11 | yew = { path = "../../../yew" } 12 | yewtil = { path = "../.." } 13 | -------------------------------------------------------------------------------- /examples/large_table/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Table100x100 Test 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/nested_list/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Nested List 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /yewtil/examples/dsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dsl" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | 8 | [dependencies] 9 | log = "0.4.8" 10 | wasm-logger = "0.2.0" 11 | yew = { path = "../../../yew" } 12 | yewtil = { path = "../..", features = ["dsl"] } 13 | -------------------------------------------------------------------------------- /yewtil/examples/lrc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lrc" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | 8 | [dependencies] 9 | log = "0.4.8" 10 | wasm-logger = "0.2.0" 11 | yew = { path = "../../../yew" } 12 | yewtil = { path = "../..", features = ["lrc"] } 13 | -------------------------------------------------------------------------------- /yewtil/examples/pure_component/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pure_component" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | 8 | [dependencies] 9 | log = "0.4.8" 10 | wasm-logger = "0.2.0" 11 | yew = { path = "../../../yew" } 12 | yewtil = { path = "../.." } 13 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-list-pass.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_pass() { 4 | html! {}; 5 | html! { <> }; 6 | html! { 7 | <> 8 | <> 9 | <> 10 | 11 | }; 12 | html! { 13 | 14 | 15 | }; 16 | } 17 | 18 | fn main() {} 19 | -------------------------------------------------------------------------------- /yewtil-macro/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate proc_macro; 2 | use proc_macro::TokenStream; 3 | 4 | use crate::function_component::function_component_handler; 5 | 6 | mod function_component; 7 | #[proc_macro_attribute] 8 | pub fn function_component(attr: TokenStream, item: TokenStream) -> TokenStream { 9 | function_component_handler(attr.into(), item) 10 | } 11 | -------------------------------------------------------------------------------- /examples/js_callback/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | (Asynchronous) callback from JavaScript 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /yewtil/examples/fetch/Readme.md: -------------------------------------------------------------------------------- 1 | Shows off ergonomic JSON deserialization fetch abstraction. 2 | 3 | Run with: 4 | 5 | ```shell script 6 | wasm-pack build --target web && rollup ./main.js --format iife --file ./pkg/bundle.js && python -m SimpleHTTPServer 8080 7 | ``` 8 | 9 | It is expected that you have a setup with wasm-pack, rollup, and python installed. 10 | -------------------------------------------------------------------------------- /examples/npm_and_rest/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • npm and REST 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /yew-stdweb/examples/js_callback/README.md: -------------------------------------------------------------------------------- 1 | (Asynchronous) callback from Javascript 2 | ======================================= 3 | 4 | The purpose of this example is to demonstrate a simple case of asynchronously 5 | sending a message back into the component update loop. 6 | 7 | See https://github.com/yewstack/yew/issues/316 for discussion on what 8 | motivated this example. 9 | -------------------------------------------------------------------------------- /yew-stdweb/examples/js_callback/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | (Asynchronous) callback from JavaScript 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /yew-router/examples/servers/warp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "warp" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | warp = "0.2.2" 11 | tokio = {version = "0.2.19", features = ["macros"]} 12 | -------------------------------------------------------------------------------- /yew-stdweb/examples/npm_and_rest/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • npm and REST 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/game_of_life/src/main.rs: -------------------------------------------------------------------------------- 1 | use game_of_life::{Model, Msg}; 2 | use log::trace; 3 | use yew::App; 4 | 5 | fn main() { 6 | wasm_logger::init(wasm_logger::Config::default()); 7 | trace!("Initializing yew..."); 8 | yew::initialize(); 9 | App::::new() 10 | .mount_to_body() 11 | .send_message(Msg::Random); 12 | yew::run_loop(); 13 | } 14 | -------------------------------------------------------------------------------- /examples/inner_html/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "inner_html" 3 | version = "0.1.0" 4 | authors = ["Garrett Berg "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | 10 | [dependencies.web-sys] 11 | version = "0.3" 12 | features = [ 13 | "console", 14 | "Document", 15 | "Element", 16 | "Node", 17 | "Window", 18 | ] 19 | -------------------------------------------------------------------------------- /examples/npm_and_rest/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "npm_and_rest" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | anyhow = "1" 9 | js-sys = "0.3" 10 | serde = "1" 11 | serde_derive = "1" 12 | wasm-bindgen = "0.2" 13 | web-sys = { version = "0.3", features = ["console"] } 14 | yew = { path = "../../yew" } 15 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-block-fail.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_fail() { 4 | html! { 5 | <> 6 | { () } 7 | 8 | }; 9 | 10 | let not_tree = || (); 11 | html! { 12 |
{ not_tree() }
13 | }; 14 | html! { 15 | <>{ for (0..3).map(|_| not_tree()) } 16 | }; 17 | } 18 | 19 | fn main() {} 20 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-list-fail.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_fail() { 4 | html! { <> }; 5 | html! { }; 6 | html! { <><> }; 7 | html! { }; 8 | html! { <><> }; 9 | html! { <><> }; 10 | html! { <>invalid }; 11 | html! { } 12 | html! { invalid} 13 | } 14 | 15 | fn main() {} 16 | -------------------------------------------------------------------------------- /yew-router-route-parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-router-route-parser" 3 | version = "0.12.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | description = "The parser for the routing syntax used with yew-router" 8 | repository = "https://github.com/yewstack/yew_router" 9 | 10 | [dependencies] 11 | nom = "5.0.0" 12 | -------------------------------------------------------------------------------- /yew-stdweb/examples/file_upload/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "file_upload" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../..", package = "yew-stdweb" } 9 | 10 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 11 | wasm-bindgen = "0.2.60" 12 | -------------------------------------------------------------------------------- /examples/game_of_life/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "game_of_life" 3 | version = "0.1.3" 4 | authors = ["Diego Cardoso ", 5 | "Ilya Bogdanov "] 7 | edition = "2018" 8 | 9 | [dependencies] 10 | rand = "0.7.3" 11 | log = "0.4" 12 | wasm-logger = "0.2.0" 13 | yew = { path = "../../yew" } 14 | -------------------------------------------------------------------------------- /yew-router/examples/servers/actix/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "actix" 3 | version = "0.1.0" 4 | authors = ["tarkah "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | actix-web = "2.0.0" 11 | actix-files = "0.2.1" 12 | actix-rt = "1.1.0" 13 | env_logger = "0.7.1" 14 | -------------------------------------------------------------------------------- /examples/game_of_life/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Game of Life 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/counter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "counter" 3 | version = "0.1.1" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/inner_html/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "inner_html" 3 | version = "0.1.0" 4 | authors = ["Garrett Berg "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/mount_point/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mount_point" 3 | version = "0.1.0" 4 | authors = ["Ben Berman "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/js_callback/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "js_callback" 3 | version = "0.1.0" 4 | authors = ["Scott Steele "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/node_refs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "node_refs" 3 | version = "0.1.0" 4 | authors = ["Justin Starry "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/two_apps/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "two_apps" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | yew = { path = "../..", package = "yew-stdweb" } 10 | 11 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 12 | wasm-bindgen = "0.2.60" 13 | 14 | -------------------------------------------------------------------------------- /examples/large_table/static/styles.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | margin: 0; 4 | padding: 0; 5 | text-align: center; 6 | } 7 | 8 | body { 9 | width: 1000px; 10 | height: 1000px; 11 | } 12 | 13 | tr { 14 | height: 10px; 15 | } 16 | td { 17 | width: 10px; 18 | } 19 | 20 | .square_red { 21 | background-color: #aaaaff 22 | } 23 | 24 | .square_green{ 25 | background-color: #aa5555 26 | } 27 | -------------------------------------------------------------------------------- /examples/two_apps/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Two Apps 6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /yewtil/examples/function_component/src/button.rs: -------------------------------------------------------------------------------- 1 | use yew::{html, Callback, Html, MouseEvent}; 2 | use yewtil::function_component; 3 | 4 | #[function_component(Button)] 5 | pub fn button( 6 | callback: &Callback, 7 | #[prop_or_default] text: String, 8 | #[prop_or_default] _num: usize, 9 | ) -> Html { 10 | html! { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-iterable-fail.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_fail() { 4 | html! { for }; 5 | html! { for () }; 6 | html! { for {()} }; 7 | html! { for Vec::<()>::new().into_iter() }; 8 | 9 | let empty = Vec::<()>::new().into_iter(); 10 | html! { for empty }; 11 | 12 | let empty = Vec::<()>::new(); 13 | html! { for empty.iter() }; 14 | } 15 | 16 | fn main() {} 17 | -------------------------------------------------------------------------------- /yewtil/examples/fetch/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fetch" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib", "rlib"] 9 | 10 | [dependencies] 11 | log = "0.4.8" 12 | serde = "1.0.102" 13 | wasm-bindgen = "0.2.51" 14 | wasm-logger = "0.2.0" 15 | yew = { path = "../../../yew" } 16 | yewtil = { path = "../..", features = ["fetch"] } 17 | -------------------------------------------------------------------------------- /yew-stdweb/examples/two_apps/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • Two Apps 6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /yew-router/examples/router_component/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "router_component" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib", "rlib"] 9 | 10 | [dependencies] 11 | yew = { path = "../../../yew" } 12 | yew-router = { path = "../.." } 13 | wasm-logger = "0.2.0" 14 | log = "0.4.8" 15 | wee_alloc = "0.4.5" 16 | wasm-bindgen = "0.2.60" 17 | -------------------------------------------------------------------------------- /yewtil-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yewtil-macro" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | description = "Macros to be re-exported from the yewtil crate" 8 | 9 | [lib] 10 | proc-macro = true 11 | 12 | [dependencies] 13 | proc-macro2 = "1.0.6" 14 | quote = "1.0.2" 15 | syn = { version = "1.0.11", features = ["full", "extra-traits"] } 16 | -------------------------------------------------------------------------------- /yewtil/examples/function_component/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "function_component" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | log = "0.4.8" 9 | wasm-logger = "0.2.0" 10 | yew = { path = "../../../yew" } 11 | yewtil = { path = "../.." } 12 | 13 | [target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'.dependencies] 14 | wasm-bindgen = "0.2.51" 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ask-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask question 3 | about: Ask for help or clarification 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | #### Question 14 | 15 | 16 | #### What I've tried (optional) 17 | -------------------------------------------------------------------------------- /examples/minimal_wp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "minimal_wp" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | yew = { path = "../../yew" } 9 | wasm-bindgen = "0.2" 10 | 11 | 12 | # requirement of wasm-pack which builds crates as libraries 13 | # it is required to have `#[wasm_bindgen(start)]` in lib.rs as starting point 14 | [lib] 15 | crate-type = ["cdylib", "rlib"] 16 | -------------------------------------------------------------------------------- /yew-stdweb/examples/npm_and_rest/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "npm_and_rest" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | anyhow = "1" 9 | serde = "1" 10 | serde_derive = "1" 11 | stdweb = "0.4.20" 12 | yew = { path = "../..", package = "yew-stdweb" } 13 | 14 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 15 | wasm-bindgen = "0.2.60" -------------------------------------------------------------------------------- /yew-stdweb/examples/todomvc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todomvc" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | strum = "0.13" 9 | strum_macros = "0.13" 10 | serde = "1" 11 | serde_derive = "1" 12 | yew = { path = "../..", package = "yew-stdweb" } 13 | 14 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 15 | wasm-bindgen = "0.2.60" 16 | -------------------------------------------------------------------------------- /examples/mount_point/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mount_point" 3 | version = "0.1.0" 4 | authors = ["Ben Berman "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | wasm-bindgen = "0.2" 9 | yew = { path = "../../yew" } 10 | 11 | [dependencies.web-sys] 12 | version = "0.3" 13 | features = [ 14 | "CanvasRenderingContext2d", 15 | "Document", 16 | "DomTokenList", 17 | "Element", 18 | "HtmlCanvasElement", 19 | "Node", 20 | "Window" 21 | ] 22 | -------------------------------------------------------------------------------- /examples/multi_thread/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "multi_thread" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [[bin]] 8 | name = "multi_thread_app" 9 | path = "src/bin/app.rs" 10 | 11 | [[bin]] 12 | name = "multi_thread_worker" 13 | path = "src/bin/native_worker.rs" 14 | 15 | [dependencies] 16 | log = "0.4" 17 | wasm-logger = "0.2" 18 | serde = "1.0" 19 | serde_derive = "1.0" 20 | yew = { path = "../../yew" } 21 | -------------------------------------------------------------------------------- /examples/todomvc/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • TodoMVC 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /yew-router/examples/minimal/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "minimal-router" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib", "rlib"] 9 | 10 | [dependencies] 11 | yew = { path = "../../../yew" } 12 | yew-router = { path = "../..", features = ["service", "web_sys"], default-features = false } 13 | wasm-logger = "0.2.0" 14 | log = "0.4.8" 15 | wee_alloc = "0.4.5" 16 | wasm-bindgen = "0.2.60" 17 | -------------------------------------------------------------------------------- /examples/webgl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webgl" 3 | version = "0.1.0" 4 | authors = ["Miklós Tusz "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | js-sys = "0.3" 9 | yew = { path = "../../yew" } 10 | wasm-bindgen = "0.2" 11 | 12 | [dependencies.web-sys] 13 | version = "0.3" 14 | features = [ 15 | 'HtmlCanvasElement', 16 | 'WebGlBuffer', 17 | 'WebGlProgram', 18 | 'WebGlRenderingContext', 19 | 'WebGlShader', 20 | 'WebGlUniformLocation', 21 | ] 22 | -------------------------------------------------------------------------------- /yew-stdweb/examples/todomvc/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Yew • TodoMVC 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /yew-stdweb/examples/webgl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webgl" 3 | version = "0.1.0" 4 | authors = ["Miklós Tusz "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | stdweb = "0.4.20" 9 | webgl_stdweb = {version = "0.3.0", optional = true} 10 | yew = { path = "../..", package = "yew-stdweb" } 11 | 12 | # Used to fix CI (most projects won't need this) 13 | [target.'cfg(any(not(target_arch = "wasm32"), target_os="wasi", cargo_web))'.dependencies] 14 | webgl_stdweb = "0.3.0" 15 | -------------------------------------------------------------------------------- /yewtil/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 15 | 16 | ## ✨ **v0.2.0** *11/18/19* 17 | - #### ⚡️ Features 18 | - Add new `FetchRequest` trait, `fetch_resource()` function, and `FetchState` enum 19 | to simplify making fetch requests using futures. 20 | - Add `Default` implementations to `Irc` and `Mrc`. 21 | -------------------------------------------------------------------------------- /.static/yew.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-iterable-pass.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | use std::iter; 3 | 4 | fn compile_pass() { 5 | html! { for iter::empty::() }; 6 | html! { for Vec::::new() }; 7 | html! { for Vec::::new().into_iter() }; 8 | html! { for (0..3).map(|num| { html! { {num} } }) }; 9 | html! { for {iter::empty::()} }; 10 | 11 | let empty: Vec = Vec::new(); 12 | html! { for empty.into_iter() }; 13 | 14 | let empty: Vec = Vec::new(); 15 | html! { for empty }; 16 | } 17 | 18 | fn main() {} 19 | -------------------------------------------------------------------------------- /yewtil/src/ptr/mod.rs: -------------------------------------------------------------------------------- 1 | //! Smart pointers for use within Yew. 2 | //! 3 | //! These all offer similar semantics to `std::rc::Rc`, but offer better ergonomics within Yew, 4 | //! or functionality not available in `Rc`. 5 | #[cfg(feature = "mrc_irc")] 6 | mod irc; 7 | #[cfg(feature = "lrc")] 8 | mod lrc; 9 | #[cfg(feature = "mrc_irc")] 10 | mod mrc; 11 | mod rc_box; 12 | mod takeable; 13 | 14 | #[cfg(feature = "mrc_irc")] 15 | pub use irc::Irc; 16 | #[cfg(feature = "lrc")] 17 | pub use lrc::Lrc; 18 | #[cfg(feature = "mrc_irc")] 19 | pub use mrc::Mrc; 20 | 21 | pub(crate) type IsZero = bool; 22 | -------------------------------------------------------------------------------- /ci/install_cargo_web.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | IFS=$'\n\t' 5 | 6 | CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest) 7 | CARGO_WEB_VERSION=$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') 8 | CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz" 9 | 10 | echo "Downloading cargo-web from: $CARGO_WEB_URL" 11 | curl -L $CARGO_WEB_URL | gzip -d > cargo-web 12 | chmod +x cargo-web 13 | 14 | mkdir -p ~/.cargo/bin 15 | mv cargo-web ~/.cargo/bin 16 | -------------------------------------------------------------------------------- /yew-stdweb/examples/multi_thread/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "multi_thread" 3 | version = "0.1.0" 4 | authors = ["Denis Kolodin "] 5 | edition = "2018" 6 | 7 | [[bin]] 8 | name = "main" 9 | path = "src/bin/main.rs" 10 | 11 | [[bin]] 12 | name = "native_worker" 13 | path = "src/bin/native_worker.rs" 14 | 15 | [dependencies] 16 | log = "0.4" 17 | web_logger = "0.2" 18 | serde = "1.0" 19 | serde_derive = "1.0" 20 | yew = { path = "../..", package = "yew-stdweb" } 21 | 22 | [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] 23 | wasm-bindgen = "0.2.60" 24 | 25 | -------------------------------------------------------------------------------- /yew-router/examples/README.md: -------------------------------------------------------------------------------- 1 | # Yew Router Examples 2 | - minimal - Demonstrates how to use this library without the use of the Router component. 3 | - router_component - Shows off the preferred way for how to use this library. 4 | 5 | - switch - Various examples for how to construct routes with the router. 6 | 7 | ## Running 8 | Details on how to build and run these examples can be found in the readme under `servers/`. 9 | 10 | Using the router in its expected use case (not fragment routing) requires that the server respond to requests for 11 | resources at URLs that are routes within the router with the index.html of the application. 12 | -------------------------------------------------------------------------------- /yewtil/examples/pure_component/src/button.rs: -------------------------------------------------------------------------------- 1 | use yew::virtual_dom::VNode; 2 | use yew::{html, Callback, MouseEvent, Properties}; 3 | use yewtil::{Pure, PureComponent}; 4 | 5 | /// Alias to make usability better. 6 | pub type Button = Pure; 7 | 8 | #[derive(Clone, PartialEq, Properties)] 9 | pub struct PureButton { 10 | pub callback: Callback, 11 | #[prop_or_default] 12 | pub text: String, 13 | } 14 | 15 | impl PureComponent for PureButton { 16 | fn render(&self) -> VNode { 17 | html! { 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /yewtil/src/dsl/vtext.rs: -------------------------------------------------------------------------------- 1 | use crate::dsl::BoxedVNodeProducer; 2 | use yew::virtual_dom::VText; 3 | use yew::Component; 4 | 5 | pub struct VTextProducer(Box VText>); 6 | 7 | impl VTextProducer { 8 | pub fn new + 'static>(text: T) -> Self { 9 | VTextProducer(Box::new(move || VText::new(text.into()))) 10 | } 11 | } 12 | 13 | impl From> for BoxedVNodeProducer { 14 | fn from(vtext_prod: VTextProducer) -> Self { 15 | BoxedVNodeProducer::wrap(move |_scope| (vtext_prod.0)().into()) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: automatic merge on CI success - admin 3 | conditions: 4 | - author=@yewstack/maintainers 5 | - status-success=Travis CI - Pull Request 6 | - label=automerge 7 | actions: 8 | merge: 9 | method: rebase 10 | - name: remove automerge label on CI failure 11 | conditions: 12 | - status-failure=Travis CI - Pull Request 13 | - label=automerge 14 | actions: 15 | label: 16 | remove: 17 | - automerge 18 | - name: remove outdated reviews 19 | conditions: 20 | - base=master 21 | actions: 22 | dismiss_reviews: {} 23 | -------------------------------------------------------------------------------- /examples/futures_wp/README.md: -------------------------------------------------------------------------------- 1 | # Futures Example 2 | This example shows off how to make a asynchronous fetch request using web_sys and Yew's futures support. 3 | 4 | ### How to run: 5 | This example requires rustc v1.39.0 or above to compile due to its use of async/.await syntax. 6 | 7 | ```sh 8 | wasm-pack build --target web --out-dir ../static/ --out-name wasm && python -m SimpleHTTPServer 8080 9 | ``` 10 | 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. 11 | 12 | It is expected that you have a setup with wasm-pack and python installed. 13 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-node-pass.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_pass() { 4 | html! { "" }; 5 | html! { 'a' }; 6 | html! { "hello" }; 7 | html! { 42 }; 8 | html! { 1.234 }; 9 | html! { true }; 10 | 11 | html! { { "" } }; 12 | html! { { 'a' } }; 13 | html! { { "hello" } }; 14 | html! { { 42 } }; 15 | html! { { 1.234 } }; 16 | html! { { true } }; 17 | 18 | html! { format!("Hello") }; 19 | html! { String::from("Hello") }; 20 | 21 | let msg = "Hello"; 22 | html! { msg }; 23 | } 24 | 25 | fn main() {} 26 | -------------------------------------------------------------------------------- /yew/src/format/toml.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of TOML serialization format. 2 | 3 | /// A representation of a TOML data. Use it as wrapper to 4 | /// set a format you want to use for conversion: 5 | /// 6 | /// ``` 7 | /// // Converts (lazy) data to a Toml 8 | ///# use yew::format::Toml; 9 | ///# fn dont_execute() { 10 | ///# let data: String = unimplemented!(); 11 | /// let dump = Toml(&data); 12 | /// 13 | /// // Converts TOML string to a data (lazy). 14 | /// let Toml(data) = dump; 15 | /// } 16 | /// ``` 17 | #[derive(Debug)] 18 | pub struct Toml(pub T); 19 | 20 | text_format!(Toml based on toml); 21 | 22 | binary_format!(Toml based on toml); 23 | -------------------------------------------------------------------------------- /examples/futures_wp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "futures_wp" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | description = "web_sys fetching and futures demonstration" 7 | license = "MIT/Apache" 8 | repository = "https://github.com/yewstack/yew" 9 | 10 | [lib] 11 | crate-type = ["cdylib", "rlib"] 12 | 13 | [dependencies] 14 | yew = { path = "../../yew" } 15 | wasm-bindgen = "0.2.60" 16 | wasm-bindgen-futures = "0.4.3" 17 | 18 | [dependencies.web-sys] 19 | version = "0.3.35" 20 | features = [ 21 | 'Headers', 22 | 'Request', 23 | 'RequestInit', 24 | 'RequestMode', 25 | 'Response', 26 | 'Window', 27 | ] 28 | -------------------------------------------------------------------------------- /examples/server/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::net::TcpListener; 2 | use std::thread::spawn; 3 | use tungstenite::server::accept; 4 | 5 | fn main() { 6 | let server = TcpListener::bind("127.0.0.1:9001").unwrap(); 7 | for stream in server.incoming() { 8 | spawn(move || { 9 | let mut websocket = accept(stream.unwrap()).unwrap(); 10 | loop { 11 | let msg = websocket.read_message().unwrap(); 12 | println!("Received: {}", msg); 13 | if msg.is_binary() || msg.is_text() { 14 | websocket.write_message(msg).unwrap(); 15 | } 16 | } 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /yew-router-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-router-macro" 3 | version = "0.12.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | license = "MIT/Apache-2.0" 7 | description = "Contains macros used with yew-router" 8 | repository = "https://github.com/yewstack/yew_router" 9 | 10 | [lib] 11 | proc-macro = true 12 | 13 | [dependencies] 14 | syn = "1.0.2" 15 | quote = "1.0.1" 16 | yew-router-route-parser = { version = "0.12.0", path = "../yew-router-route-parser"} 17 | proc-macro2 = "1.0.1" 18 | 19 | [dev-dependencies] 20 | yew-router = { path = "../yew-router" } # This should probably be removed, it makes the deploy process much more annoying. -------------------------------------------------------------------------------- /yew-stdweb/examples/README.md: -------------------------------------------------------------------------------- 1 | # Yew Examples 2 | 3 | ### Running the examples 4 | 5 | To start an example, enter its directory and start it with [cargo-web]: 6 | 7 | ```bash 8 | cargo web start 9 | ``` 10 | 11 | To run an optimized build instead of a debug build use: 12 | 13 | ```bash 14 | cargo web start --release 15 | ``` 16 | 17 | The `wasm32-unknown-unknown` target will be used by default, which is Rust's native WebAssembly target. The Emscripten-based `wasm32-unknown-emscripten` and `asmjs-unknown-emscripten` targets are also supported if you tell the `cargo-web` to build for them using the `--target` parameter. 18 | 19 | [cargo-web]: https://github.com/koute/cargo-web 20 | -------------------------------------------------------------------------------- /yew/build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | pub fn main() { 4 | let using_web_sys = cfg!(feature = "web_sys"); 5 | let using_std_web = cfg!(feature = "std_web"); 6 | if using_web_sys && using_std_web { 7 | panic!("Yew does not allow the `web_sys` and `std_web` cargo features to be used simultaneously"); 8 | } else if !using_web_sys && !using_std_web { 9 | panic!("Yew requires selecting either the `web_sys` or `std_web` cargo feature"); 10 | } 11 | 12 | let using_cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").is_ok(); 13 | if using_cargo_web && using_web_sys { 14 | panic!("cargo-web is not compatible with web-sys"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: deniskolodin 5 | open_collective: yew 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /yew/src/format/yaml.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of YAML serialization format. 2 | 3 | use serde_yaml; 4 | 5 | /// A representation of a YAML data. Use it as wrapper to 6 | /// set a format you want to use for conversion: 7 | /// 8 | /// ``` 9 | /// // Converts (lazy) data to a Yaml 10 | ///# use yew::format::Yaml; 11 | /// 12 | ///# fn dont_execute() { 13 | ///# let data: String = unimplemented!(); 14 | /// let dump = Yaml(&data); 15 | /// 16 | /// // Converts YAML string to a data (lazy). 17 | /// let Yaml(data) = dump; 18 | ///# } 19 | /// ``` 20 | #[derive(Debug)] 21 | pub struct Yaml(pub T); 22 | 23 | text_format!(Yaml based on serde_yaml); 24 | 25 | binary_format!(Yaml based on serde_yaml); 26 | -------------------------------------------------------------------------------- /yewtil/examples/futures/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "futures-yewtil" 3 | version = "0.1.0" 4 | authors = ["Henry Zimmerman "] 5 | edition = "2018" 6 | description = "web_sys fetching and futures demonstration" 7 | license = "MIT/Apache" 8 | repository = "https://github.com/yewstack/yew" 9 | 10 | [lib] 11 | crate-type = ["cdylib", "rlib"] 12 | 13 | [dependencies] 14 | wasm-bindgen = "0.2.51" 15 | wasm-bindgen-futures = "0.4.3" 16 | yew = { path = "../../../yew" } 17 | yewtil = { path = "../.." } 18 | 19 | [dependencies.web-sys] 20 | version = "0.3.30" 21 | features = [ 22 | 'Headers', 23 | 'Request', 24 | 'RequestInit', 25 | 'RequestMode', 26 | 'Response', 27 | 'Window', 28 | ] 29 | -------------------------------------------------------------------------------- /yew-components/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-components" 3 | version = "0.1.0" 4 | edition = "2018" 5 | authors = [ 6 | "Yew Maintainers ", 7 | ] 8 | repository = "https://github.com/yewstack/yew" 9 | homepage = "https://github.com/yewstack/yew" 10 | documentation = "https://docs.rs/yew-components/" 11 | license = "MIT/Apache-2.0" 12 | keywords = ["web", "asmjs", "webasm", "javascript"] 13 | categories = ["gui", "web-programming"] 14 | description = "A collection of community-created Yew components" 15 | 16 | [badges] 17 | travis-ci = { repository = "yewstack/yew" } 18 | 19 | [dependencies] 20 | wasm-bindgen = "0.2.60" 21 | web-sys = "0.3" 22 | yew = { version = "0.15", path = "../yew" } 23 | -------------------------------------------------------------------------------- /yew/src/format/cbor.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of CBOR serialization format. 2 | 3 | use serde_cbor; 4 | 5 | /// A representation of a CBOR data. Use it as wrapper to 6 | /// set a format you want to use for conversion: 7 | /// 8 | /// ``` 9 | /// // Converts (lazy) data to a Cbor 10 | ///# use yew::format::Cbor; 11 | ///# fn dont_execute() { 12 | ///# let data: String = unimplemented!(); 13 | /// let dump = Cbor(&data); 14 | /// 15 | /// // Converts CBOR string to a data (lazy). 16 | /// let Cbor(data) = dump; 17 | ///# } 18 | /// ``` 19 | /// This is a binary only format. 20 | #[derive(Debug)] 21 | pub struct Cbor(pub T); 22 | 23 | binary_format!(Cbor based on serde_cbor); 24 | text_format_is_an_error!(Cbor); 25 | -------------------------------------------------------------------------------- /examples/multi_thread/README.md: -------------------------------------------------------------------------------- 1 | ### multi_thread 2 | 3 | First, build your web app 4 | 5 | ```sh 6 | cargo build --target wasm32-unknown-unknown --bin multi_thread_app 7 | wasm-bindgen --target web --no-typescript --out-dir static/ --out-name app ../../target/wasm32-unknown-unknown/debug/multi_thread_app.wasm 8 | ``` 9 | 10 | Then, build your web worker 11 | 12 | ```sh 13 | cargo build --target wasm32-unknown-unknown --bin multi_thread_worker 14 | wasm-bindgen --target no-modules --no-typescript --out-dir static/ --out-name worker ../../target/wasm32-unknown-unknown/debug/multi_thread_worker.wasm 15 | ``` 16 | 17 | Finally, serve the content from the `./static` directory 18 | 19 | ```sh 20 | python3 -m http.server 21 | ``` 22 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-node-fail.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_fail() { 4 | html! { "valid" "invalid" }; 5 | html! { { "valid" "invalid" } }; 6 | html! { () }; 7 | html! { invalid }; 8 | 9 | // unsupported literals 10 | html! { b'a' }; 11 | html! { b"str" }; 12 | html! { 1111111111111111111111111111111111111111111111111111111111111111111111111111 }; 13 | html! { { b'a' } }; 14 | html! { { b"str" } }; 15 | html! { { 1111111111111111111111111111111111111111111111111111111111111111111111111111 } }; 16 | 17 | let not_node = || (); 18 | html! { 19 | not_node() 20 | }; 21 | } 22 | 23 | fn main() {} 24 | -------------------------------------------------------------------------------- /yew-router/examples/minimal/README.md: -------------------------------------------------------------------------------- 1 | # Minimal Example 2 | Run with `cargo web start`. 3 | 4 | This example shows how to use this library with only the "service" feature turned on. 5 | Without most of the features, you lack the `Router` component and `RouteAgent` and its associated bridges and dispatchers. 6 | This means that you must use the `RouteService` to interface with the browser to handle route changes. 7 | 8 | Removing the `Router` component means that you have to deal with the `RouteService` directly and propagate change route messages up to the component that contains the `RouteService`. 9 | 10 | The unit type aliases part of the prelude are not included without any features. You may want to turn that back for actual use. -------------------------------------------------------------------------------- /examples/two_apps/src/main.rs: -------------------------------------------------------------------------------- 1 | use two_apps::{Model, Msg}; 2 | use yew::html::Scope; 3 | use yew::App; 4 | 5 | fn mount_app(selector: &'static str, app: App) -> Scope { 6 | let document = yew::utils::document(); 7 | let element = document.query_selector(selector).unwrap().unwrap(); 8 | app.mount(element) 9 | } 10 | 11 | fn main() { 12 | yew::initialize(); 13 | let first_app = App::new(); 14 | let second_app = App::new(); 15 | let to_first = mount_app(".first-app", first_app); 16 | let to_second = mount_app(".second-app", second_app); 17 | to_first.send_message(Msg::SetOpposite(to_second.clone())); 18 | to_second.send_message(Msg::SetOpposite(to_first)); 19 | yew::run_loop(); 20 | } 21 | -------------------------------------------------------------------------------- /yew/src/format/bincode.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of Bincode serialization format. 2 | 3 | /// A representation of a Bincode data. Use it as wrapper to 4 | /// set a format you want to use for conversion: 5 | /// 6 | /// ```rust 7 | /// // Converts (lazy) data to a Bincode 8 | ///# use yew::format::Bincode; 9 | ///# fn dont_execute() { 10 | ///# let data: String = unimplemented!(); 11 | /// let dump = Bincode(&data); 12 | /// 13 | /// // Converts Bincode to a data (lazy). 14 | /// let Bincode(data) = dump; 15 | ///# } 16 | /// ``` 17 | /// This is a binary only format. 18 | #[derive(Debug)] 19 | pub struct Bincode(pub T); 20 | 21 | binary_format!(Bincode, bincode::serialize, bincode::deserialize); 22 | text_format_is_an_error!(Bincode); 23 | -------------------------------------------------------------------------------- /yew-functional/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-functional" 3 | version = "0.13.0" 4 | authors = ["ZainlessBrombie "] 5 | edition = "2018" 6 | repository = "https://github.com/yewstack/yew" 7 | homepage = "https://github.com/yewstack/yew" 8 | license = "MIT/Apache-2.0" 9 | keywords = ["web", "wasm", "frontend", "webasm", "webassembly"] 10 | categories = ["gui", "web-programming", "wasm"] 11 | description = "A framework for making client-side single-page apps" 12 | 13 | 14 | [badges] 15 | travis-ci = { repository = "yewstack/yew" } 16 | 17 | [dev-dependencies] 18 | wasm-bindgen-test = "0.3.9" 19 | web-sys = "0.3.36" 20 | yew = { path = "../yew" } 21 | 22 | [dependencies] 23 | yew = { path = "../yew" } 24 | wasm-bindgen = "0.2.60" 25 | -------------------------------------------------------------------------------- /yew-stdweb/examples/npm_and_rest/src/ccxt.rs: -------------------------------------------------------------------------------- 1 | use stdweb::unstable::TryInto; 2 | use stdweb::Value; 3 | 4 | #[derive(Default)] 5 | pub struct CcxtService(Option); 6 | 7 | impl CcxtService { 8 | pub fn new() -> Self { 9 | let lib = js! { 10 | return ccxt; 11 | }; 12 | CcxtService(Some(lib)) 13 | } 14 | 15 | pub fn exchanges(&mut self) -> Vec { 16 | let lib = self.0.as_ref().expect("ccxt library object lost"); 17 | let v: Value = js! { 18 | var ccxt = @{lib}; 19 | console.log(ccxt.exchanges); 20 | return ccxt.exchanges; 21 | }; 22 | let v: Vec = v.try_into().expect("can't extract exchanges"); 23 | v 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /yew/src/format/nothing.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of empty serialization format (`Nothing`). 2 | 3 | use super::{Binary, Text}; 4 | use anyhow::bail; 5 | 6 | /// A representation of an empty data. Nothing stored. Nothing restored. 7 | #[derive(Debug)] 8 | pub struct Nothing; 9 | 10 | impl Into for Nothing { 11 | fn into(self) -> Text { 12 | bail!("nothing") 13 | } 14 | } 15 | 16 | impl From for Nothing { 17 | fn from(_: Text) -> Nothing { 18 | Nothing 19 | } 20 | } 21 | 22 | impl Into for Nothing { 23 | fn into(self) -> Binary { 24 | bail!("nothing") 25 | } 26 | } 27 | 28 | impl From for Nothing { 29 | fn from(_: Binary) -> Nothing { 30 | Nothing 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/test_component.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | #[derive(Clone, Properties, PartialEq)] 4 | pub struct TestProperties { 5 | pub string: String, 6 | pub int: i32, 7 | } 8 | 9 | pub struct TestComponent; 10 | impl Component for TestComponent { 11 | type Message = (); 12 | type Properties = TestProperties; 13 | 14 | fn create(_: Self::Properties, _: ComponentLink) -> Self { 15 | TestComponent 16 | } 17 | 18 | fn update(&mut self, _: Self::Message) -> ShouldRender { 19 | unimplemented!() 20 | } 21 | 22 | fn change(&mut self, _: Self::Properties) -> ShouldRender { 23 | unimplemented!() 24 | } 25 | 26 | fn view(&self) -> Html { 27 | unimplemented!() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /yew-router-macro/src/switch/enum_impl.rs: -------------------------------------------------------------------------------- 1 | use proc_macro2::TokenStream; 2 | use quote::{quote, ToTokens}; 3 | 4 | pub use self::{build_route_section::BuildRouteSection, from_route_part::FromRoutePart}; 5 | 6 | mod build_route_section; 7 | mod from_route_part; 8 | 9 | pub struct EnumInner<'a> { 10 | pub from_route_part: FromRoutePart<'a>, 11 | pub build_route_section: BuildRouteSection<'a>, 12 | } 13 | 14 | impl<'a> ToTokens for EnumInner<'a> { 15 | fn to_tokens(&self, tokens: &mut TokenStream) { 16 | let EnumInner { 17 | from_route_part, 18 | build_route_section, 19 | } = self; 20 | tokens.extend(quote! { 21 | #from_route_part 22 | #build_route_section 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /yew-router-macro/src/switch/struct_impl.rs: -------------------------------------------------------------------------------- 1 | pub use self::{build_route_section::BuildRouteSection, from_route_part::FromRoutePart}; 2 | use proc_macro2::TokenStream; 3 | use quote::{quote, ToTokens}; 4 | 5 | mod build_route_section; 6 | mod from_route_part; 7 | 8 | pub struct StructInner<'a> { 9 | pub from_route_part: FromRoutePart<'a>, 10 | pub build_route_section: BuildRouteSection<'a>, 11 | } 12 | 13 | impl<'a> ToTokens for StructInner<'a> { 14 | fn to_tokens(&self, tokens: &mut TokenStream) { 15 | let StructInner { 16 | from_route_part, 17 | build_route_section, 18 | } = self; 19 | tokens.extend(quote! { 20 | #from_route_part 21 | #build_route_section 22 | }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /yew/src/format/msgpack.rs: -------------------------------------------------------------------------------- 1 | //! Contains an implementation of MessagePack serialization format. 2 | 3 | use rmp_serde; 4 | 5 | /// A representation of a MessagePack data. Use it as wrapper to 6 | /// set a format you want to use for conversion: 7 | /// 8 | /// ``` 9 | /// // Converts (lazy) data to a MsgPack 10 | /// 11 | ///# use yew::format::MsgPack; 12 | ///# fn dont_execute() { 13 | ///# let data: String = unimplemented!(); 14 | /// let dump = MsgPack(&data); 15 | /// 16 | /// // Converts MessagePack string to a data (lazy). 17 | /// let MsgPack(data) = dump; 18 | ///# } 19 | /// ``` 20 | /// This is a binary only protocol. 21 | #[derive(Debug)] 22 | pub struct MsgPack(pub T); 23 | 24 | binary_format!(MsgPack based on rmp_serde); 25 | text_format_is_an_error!(MsgPack); 26 | -------------------------------------------------------------------------------- /yew-stdweb/examples/two_apps/src/main.rs: -------------------------------------------------------------------------------- 1 | use stdweb::web::IParentNode; 2 | use two_apps::{Model, Msg}; 3 | use yew::html::Scope; 4 | use yew::App; 5 | 6 | fn mount_app(selector: &'static str, app: App) -> Scope { 7 | let document = yew::utils::document(); 8 | let element = document.query_selector(selector).unwrap().unwrap(); 9 | app.mount(element) 10 | } 11 | 12 | fn main() { 13 | yew::initialize(); 14 | let first_app = App::new(); 15 | let second_app = App::new(); 16 | let to_first = mount_app(".first-app", first_app); 17 | let to_second = mount_app(".second-app", second_app); 18 | to_first.send_message(Msg::SetOpposite(to_second.clone())); 19 | to_second.send_message(Msg::SetOpposite(to_first)); 20 | yew::run_loop(); 21 | } 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | **Is your feature request related to a problem? Please describe.** 13 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 14 | 15 | **Describe the solution you'd like** 16 | A clear and concise description of what you want to happen. 17 | 18 | **Describe alternatives you've considered** 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | **Additional context** 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /ci/run_stable_checks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "$(rustup default)" | grep -q "stable" 4 | if [ "$?" != "0" ]; then 5 | # only run checks on stable 6 | exit 0 7 | fi 8 | 9 | set -euxo pipefail 10 | 11 | cargo fmt --all -- --check 12 | cargo clippy --all -- --deny=warnings 13 | cargo check --all 14 | 15 | # Enable all optional features 16 | (cd yew \ 17 | && cargo check --features cbor,msgpack,toml,yaml \ 18 | && cargo clippy --features cbor,msgpack,toml,yaml -- --deny=warnings) 19 | 20 | # Check stdweb 21 | pushd yew-stdweb 22 | cargo fmt --all -- --check 23 | cargo clippy --all -- --deny=warnings 24 | cargo check --all --target wasm32-unknown-unknown 25 | 26 | # webgl_stdweb doesn't play nice with wasm-bindgen 27 | (cd examples/webgl && cargo web check --target wasm32-unknown-unknown) 28 | popd -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-block-pass.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | fn compile_pass() { 4 | html! { <>{ "Hi" } }; 5 | html! { <>{ format!("Hello") } }; 6 | html! { <>{ String::from("Hello") } }; 7 | 8 | let msg = "Hello"; 9 | html! {
{ msg }
}; 10 | 11 | let subview = html! { "subview!" }; 12 | html! {
{ subview }
}; 13 | 14 | let subview = || html! { "subview!" }; 15 | html! {
{ subview() }
}; 16 | 17 | html! { 18 |
    19 | { for (0..3).map(|num| { html! { {num} }}) } 20 |
21 | }; 22 | 23 | let item = |num| html! {
  • {format!("item {}!", num)}
  • }; 24 | html! { 25 |
      26 | { for (0..3).map(item) } 27 |
    28 | }; 29 | } 30 | 31 | fn main() {} 32 | -------------------------------------------------------------------------------- /yewtil/src/dsl/vcomp.rs: -------------------------------------------------------------------------------- 1 | use crate::dsl::BoxedVNodeProducer; 2 | use yew::virtual_dom::vcomp::ScopeHolder; 3 | use yew::virtual_dom::VComp; 4 | use yew::{Component, NodeRef}; 5 | 6 | pub struct VCompProducer(Box) -> VComp>); 7 | 8 | impl VCompProducer { 9 | pub fn new(props: CHILD::Properties) -> Self { 10 | // TODO allow getting the noderef as a parameter somewhere. 11 | VCompProducer(Box::new(move |scope| VComp::new::(props, scope, NodeRef::default()))) 12 | } 13 | } 14 | 15 | impl From> for BoxedVNodeProducer { 16 | fn from(vcomp_prod: VCompProducer) -> Self { 17 | BoxedVNodeProducer::wrap(move |scope| (vcomp_prod.0)(scope).into()) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /yew-router/examples/router_component/src/c_component.rs: -------------------------------------------------------------------------------- 1 | use yew::{prelude::*, virtual_dom::VNode, Properties}; 2 | 3 | pub struct CModel; 4 | 5 | #[derive(Clone, PartialEq, Properties)] 6 | pub struct Props {} 7 | 8 | pub enum Msg {} 9 | 10 | impl Component for CModel { 11 | type Message = Msg; 12 | type Properties = Props; 13 | 14 | fn create(_props: Self::Properties, _link: ComponentLink) -> Self { 15 | CModel 16 | } 17 | 18 | fn update(&mut self, _msg: Self::Message) -> ShouldRender { 19 | false 20 | } 21 | 22 | fn change(&mut self, _props: Self::Properties) -> ShouldRender { 23 | true 24 | } 25 | 26 | fn view(&self) -> VNode { 27 | html! { 28 |
    29 | {" I am the C component"} 30 |
    31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /yewtil/examples/futures/README.md: -------------------------------------------------------------------------------- 1 | # Futures Example 2 | This example shows off how to make a asynchronous fetch request using web_sys and Yew's futures support. 3 | 4 | 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. 5 | 6 | ### How to run: 7 | This example requires rustc v1.39.0 or above to compile due to its use of async/.await syntax. 8 | 9 | ```sh 10 | wasm-pack build --target web && rollup ./main.js --format iife --file ./pkg/bundle.js && python -m SimpleHTTPServer 8080 11 | ``` 12 | 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. 13 | 14 | It is expected that you have a setup with wasm-pack, rollup, and python installed. 15 | -------------------------------------------------------------------------------- /examples/pub_sub/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "128"] 2 | 3 | mod event_bus; 4 | mod producer; 5 | mod subscriber; 6 | 7 | use producer::Producer; 8 | use subscriber::Subscriber; 9 | use yew::{html, Component, ComponentLink, Html, ShouldRender}; 10 | 11 | pub struct Model {} 12 | 13 | impl Component for Model { 14 | type Message = (); 15 | type Properties = (); 16 | 17 | fn create(_: Self::Properties, _: ComponentLink) -> Self { 18 | Model {} 19 | } 20 | 21 | fn change(&mut self, _: Self::Properties) -> bool { 22 | false 23 | } 24 | 25 | fn update(&mut self, _: Self::Message) -> ShouldRender { 26 | false 27 | } 28 | 29 | fn view(&self) -> Html { 30 | html! { 31 |
    32 | 33 | 34 |
    35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/nested_list/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "512"] 2 | 3 | mod app; 4 | mod header; 5 | mod item; 6 | mod list; 7 | 8 | pub use app::App; 9 | use std::cell::RefCell; 10 | use std::fmt; 11 | use std::rc::Rc; 12 | use yew::html::ComponentLink; 13 | pub type WeakComponentLink = Rc>>>; 14 | 15 | #[derive(Debug)] 16 | pub enum Hovered { 17 | Header, 18 | Item(String), 19 | List, 20 | None, 21 | } 22 | 23 | impl fmt::Display for Hovered { 24 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 25 | write!( 26 | f, 27 | "{}", 28 | match self { 29 | Hovered::Header => "Header", 30 | Hovered::Item(name) => name, 31 | Hovered::List => "List container", 32 | Hovered::None => "Nothing", 33 | } 34 | ) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /yew-macro/tests/macro_test.rs: -------------------------------------------------------------------------------- 1 | #[allow(dead_code)] 2 | #[rustversion::attr(stable(1.43), test)] 3 | fn tests() { 4 | let t = trybuild::TestCases::new(); 5 | 6 | t.pass("tests/macro/html-block-pass.rs"); 7 | t.compile_fail("tests/macro/html-block-fail.rs"); 8 | 9 | t.pass("tests/macro/html-component-pass.rs"); 10 | t.compile_fail("tests/macro/html-component-fail.rs"); 11 | t.compile_fail("tests/macro/html-component-fail-unimplemented.rs"); 12 | 13 | t.pass("tests/macro/html-iterable-pass.rs"); 14 | t.compile_fail("tests/macro/html-iterable-fail.rs"); 15 | 16 | t.pass("tests/macro/html-list-pass.rs"); 17 | t.compile_fail("tests/macro/html-list-fail.rs"); 18 | 19 | t.pass("tests/macro/html-node-pass.rs"); 20 | t.compile_fail("tests/macro/html-node-fail.rs"); 21 | 22 | t.pass("tests/macro/html-tag-pass.rs"); 23 | t.compile_fail("tests/macro/html-tag-fail.rs"); 24 | } 25 | -------------------------------------------------------------------------------- /examples/minimal/src/lib.rs: -------------------------------------------------------------------------------- 1 | use yew::{html, Component, ComponentLink, Html, ShouldRender}; 2 | 3 | pub struct Model { 4 | link: ComponentLink, 5 | } 6 | 7 | pub enum Msg { 8 | Click, 9 | } 10 | 11 | impl Component for Model { 12 | type Message = Msg; 13 | type Properties = (); 14 | 15 | fn create(_: Self::Properties, link: ComponentLink) -> Self { 16 | Model { link } 17 | } 18 | 19 | fn change(&mut self, _: Self::Properties) -> bool { 20 | false 21 | } 22 | 23 | fn update(&mut self, msg: Self::Message) -> ShouldRender { 24 | match msg { 25 | Msg::Click => {} 26 | } 27 | true 28 | } 29 | 30 | fn view(&self) -> Html { 31 | html! { 32 |
    33 | 34 |
    35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ci/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ 3 | 4 | (cd yew \ 5 | && cargo test --target wasm32-unknown-unknown --features wasm_test \ 6 | && cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \ 7 | && cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \ 8 | --features std_web,agent,services --no-default-features) 9 | 10 | (cd yew-functional && cargo test --target wasm32-unknown-unknown) 11 | 12 | (cd yew-macro \ 13 | && cargo test --test macro_test \ 14 | && cargo test --test derive_props_test \ 15 | && cargo test --doc) 16 | 17 | (cd yew-router && cargo test) 18 | (cd yew-router-macro && cargo test) 19 | (cd yew-router-route-parser && cargo test) 20 | 21 | (cd yew-stdweb && cargo test --target wasm32-unknown-unknown --features wasm_test) 22 | 23 | (cd yewtil && cargo test) 24 | 25 | (cd yew-components && cargo test) 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - staging 4 | - trying 5 | - master 6 | 7 | dist: trusty 8 | language: rust 9 | sudo: false 10 | addons: 11 | firefox: latest 12 | 13 | cache: cargo 14 | before_cache: 15 | - ./ci/clear_cache.sh 16 | 17 | rust: 18 | - 1.40.0 # min supported 19 | - stable 20 | - beta 21 | 22 | matrix: 23 | allow_failures: 24 | - rust: beta 25 | fast_finish: true 26 | 27 | install: 28 | - nvm install 9 29 | - rustup component add rustfmt 30 | - rustup component add clippy 31 | - rustup install stable 32 | - rustup target add wasm32-unknown-unknown 33 | - cargo +stable install wasm-bindgen-cli 34 | - curl --retry 5 -LO https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz 35 | - tar -xzf geckodriver-v0.26.0-linux64.tar.gz 36 | - ./ci/install_cargo_web.sh 37 | 38 | script: 39 | - ./ci/run_stable_checks.sh 40 | - GECKODRIVER=$(pwd)/geckodriver ./ci/run_tests.sh 41 | -------------------------------------------------------------------------------- /yew-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-macro" 3 | version = "0.15.0" 4 | edition = "2018" 5 | authors = ["Justin Starry "] 6 | repository = "https://github.com/yewstack/yew" 7 | homepage = "https://github.com/yewstack/yew" 8 | documentation = "https://docs.rs/yew-macro/" 9 | license = "MIT/Apache-2.0" 10 | keywords = ["web", "wasm", "frontend", "webasm", "webassembly"] 11 | categories = ["gui", "web-programming", "wasm"] 12 | description = "A framework for making client-side single-page apps" 13 | 14 | [badges] 15 | travis-ci = { repository = "yewstack/yew" } 16 | 17 | [lib] 18 | proc-macro = true 19 | 20 | [dependencies] 21 | boolinator = "2.4.0" 22 | lazy_static = "1.3.0" 23 | proc-macro-hack = "0.5" 24 | proc-macro2 = "1.0" 25 | quote = "1.0" 26 | syn = { version = "1.0", features = ["full", "extra-traits"] } 27 | 28 | # testing 29 | [dev-dependencies] 30 | rustversion = "1.0" 31 | trybuild = "1.0" 32 | yew = { path = "../yew" } 33 | 34 | [build-dependencies] 35 | 36 | [features] 37 | doc_test = [] 38 | -------------------------------------------------------------------------------- /examples/npm_and_rest/src/ccxt.rs: -------------------------------------------------------------------------------- 1 | use js_sys::{Array, Reflect}; 2 | use wasm_bindgen::prelude::wasm_bindgen; 3 | use wasm_bindgen::JsValue; 4 | use web_sys::console; 5 | 6 | #[derive(Default)] 7 | pub struct CcxtService(Option<&'static JsValue>); 8 | 9 | #[wasm_bindgen] 10 | extern "C" { 11 | static ccxt: JsValue; 12 | } 13 | 14 | impl CcxtService { 15 | pub fn new() -> Self { 16 | let lib: &JsValue = &ccxt; 17 | CcxtService(Some(lib)) 18 | } 19 | 20 | pub fn exchanges(&mut self) -> Vec { 21 | let lib = self.0.as_ref().expect("ccxt library object lost"); 22 | let v = { 23 | let exchanges = Reflect::get(lib, &JsValue::from_str("exchanges")).unwrap(); 24 | console::log_1(&exchanges); 25 | exchanges 26 | }; 27 | let v: Vec = Array::from(&v) 28 | .to_vec() 29 | .into_iter() 30 | .map(|v| v.as_string().expect("can't extract exchanges")) 31 | .collect(); 32 | v 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /yew-stdweb/examples/mount_point/src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate stdweb; 3 | 4 | use mount_point::Model; 5 | use stdweb::web::{document, IElement, INode, IParentNode}; 6 | use yew::App; 7 | 8 | fn main() { 9 | yew::initialize(); 10 | let body = document().query_selector("body").unwrap().unwrap(); 11 | 12 | // This canvas won't be overwritten by yew! 13 | let canvas = document().create_element("canvas").unwrap(); 14 | body.append_child(&canvas); 15 | 16 | js! { 17 | const canvas = document.querySelector("canvas"); 18 | canvas.width = 100; 19 | canvas.height = 100; 20 | const ctx = canvas.getContext("2d"); 21 | ctx.fillStyle = "green"; 22 | ctx.fillRect(10, 10, 50, 50); 23 | }; 24 | 25 | let mount_class = "mount-point"; 26 | let mount_point = document().create_element("div").unwrap(); 27 | mount_point.class_list().add(mount_class).unwrap(); 28 | body.append_child(&mount_point); 29 | 30 | App::::new().mount(mount_point); 31 | yew::run_loop(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/minimal_wp/src/lib.rs: -------------------------------------------------------------------------------- 1 | use wasm_bindgen::prelude::*; 2 | use yew::{html, Component, ComponentLink, Html, ShouldRender}; 3 | 4 | pub struct Model { 5 | link: ComponentLink, 6 | } 7 | 8 | pub enum Msg { 9 | Click, 10 | } 11 | 12 | impl Component for Model { 13 | type Message = Msg; 14 | type Properties = (); 15 | 16 | fn create(_: Self::Properties, link: ComponentLink) -> Self { 17 | Model { link } 18 | } 19 | 20 | fn change(&mut self, _: Self::Properties) -> bool { 21 | false 22 | } 23 | 24 | fn update(&mut self, msg: Self::Message) -> ShouldRender { 25 | match msg { 26 | Msg::Click => {} 27 | } 28 | true 29 | } 30 | 31 | fn view(&self) -> Html { 32 | html! { 33 |
    34 | 35 |
    36 | } 37 | } 38 | } 39 | 40 | #[wasm_bindgen(start)] 41 | pub fn run_app() { 42 | yew::start_app::(); 43 | } 44 | -------------------------------------------------------------------------------- /yew-router/examples/servers/Readme.md: -------------------------------------------------------------------------------- 1 | # Example Servers 2 | 3 | These servers allow you to serve your application from any non-api route. 4 | This should prevent you from seeing 404 errors when refreshing your app after changing the route. 5 | 6 | 7 | ## Instructions 8 | 9 | If you don't already have wasm-pack installed, run: 10 | ```shell script 11 | cargo install wasm-pack 12 | ``` 13 | 14 | Change directories to your chosen example and run the following to build your wasm app. 15 | ```shell script 16 | wasm-pack build --target web --out-dir ../static/ --out-name wasm 17 | ``` 18 | 19 | Change directories again to one of the servers in this directory and run `cargo run`. 20 | They will serve files from the `static/` folder that lives in `examples/` at `localhost:8000`. 21 | 22 | 23 | ## As a template 24 | 25 | You can use these as templates for your server, or incorporate them into an existing server. 26 | You will likely have to change the assets dir constant to point elsewhere though. 27 | ```rust 28 | const ASSETS_DIR: &str = "your/assets/dir/here"; 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /ci/build_examples.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Script to build all examples in yew/examples 4 | # 5 | # Not building yew-router nor yewtil examples 6 | 7 | # src: https://gist.github.com/fbucek/f986da3cc3a9bbbd1573bdcb23fed2e1 8 | set -e # error -> trap -> exit 9 | function info() { echo -e "[\033[0;34m $@ \033[0m]"; } # blue: [ info message ] 10 | function fail() { FAIL="true"; echo -e "[\033[0;31mFAIL\033[0m] $@"; } # red: [FAIL] 11 | trap 'LASTRES=$?; LAST=$BASH_COMMAND; if [[ LASTRES -ne 0 ]]; then fail "Command: \"$LAST\" exited with exit code: $LASTRES"; elif [ "$FAIL" == "true" ]; then fail finished with error; else echo -e "[\033[0;32m Finished $@ \033[0m]";fi' EXIT 12 | SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # this source dir 13 | 14 | cd $SRCDIR/../examples # switch to examples folder 15 | 16 | for EXAMPLE in * 17 | do 18 | if [[ $EXAMPLE == static ]] || [[ $EXAMPLE == server ]] || [[ $EXAMPLE == target ]]; then 19 | echo -e "Skipping folder: $EXAMPLE" 20 | elif [ -d ${EXAMPLE} ]; then 21 | ./build.sh ${EXAMPLE} $@ 22 | fi 23 | done 24 | -------------------------------------------------------------------------------- /yewtil/examples/pure_component/src/main.rs: -------------------------------------------------------------------------------- 1 | use yew::{html, Component, ComponentLink, Html, ShouldRender}; 2 | 3 | mod button; 4 | use crate::button::Button; 5 | 6 | pub struct Model { 7 | link: ComponentLink, 8 | } 9 | 10 | pub enum Msg { 11 | DoIt, 12 | } 13 | 14 | impl Component for Model { 15 | type Message = Msg; 16 | type Properties = (); 17 | 18 | fn create(_: Self::Properties, link: ComponentLink) -> Self { 19 | Model { link } 20 | } 21 | 22 | fn update(&mut self, msg: Self::Message) -> ShouldRender { 23 | match msg { 24 | Msg::DoIt => { 25 | log::info!("got message"); 26 | true 27 | } 28 | } 29 | } 30 | 31 | fn change(&mut self, _props: ()) -> ShouldRender { 32 | false 33 | } 34 | 35 | fn view(&self) -> Html { 36 | html! { 37 | 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /yewtil/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Utility library for the Yew frontend web framework. 2 | //! 3 | //! All features: 4 | //! 5 | //! * "neq" - NeqAssign trait 6 | //! * "pure" - Pure components and function components. 7 | //! * "future" - Async support for Yew Messages 8 | //! * "fetch" - Wrapper that holds requests and responses. 9 | //! * "mrc_irc" - Ergonomic Rc pointers. 10 | //! * "lrc" - Linked-list Rc pointer. 11 | //! * "history" - History tracker 12 | // //! * "dsl" - Use functions instead of Yew's `html!` macro. 13 | 14 | //#[cfg(feature = "dsl")] 15 | //pub mod dsl; 16 | 17 | #[cfg(feature = "neq")] 18 | mod not_equal_assign; 19 | 20 | #[cfg(feature = "pure")] 21 | mod pure; 22 | 23 | #[cfg(any(feature = "mrc_irc", feature = "lrc"))] 24 | pub mod ptr; 25 | 26 | #[cfg(feature = "history")] 27 | mod history; 28 | 29 | #[cfg(feature = "history")] 30 | pub use history::History; 31 | 32 | #[cfg(feature = "neq")] 33 | pub use not_equal_assign::NeqAssign; 34 | 35 | #[cfg(feature = "pure")] 36 | pub use pure::{Pure, PureComponent}; 37 | 38 | #[cfg(feature = "pure")] 39 | pub use yewtil_macro::function_component; 40 | 41 | #[cfg(feature = "fetch")] 42 | pub mod fetch; 43 | 44 | #[cfg(feature = "effect")] 45 | mod effect; 46 | #[cfg(feature = "effect")] 47 | pub use effect::{effect, Effect}; 48 | 49 | #[cfg(feature = "future")] 50 | pub mod future; 51 | -------------------------------------------------------------------------------- /yew-macro/tests/macro/html-tag-fail.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | struct NotToString; 4 | 5 | fn compile_fail() { 6 | html! {
    }; 7 | html! {
    }; 8 | html! {
    }; 9 | html! {
    }; 10 | html! {
    }; 11 | html! {
    }; 12 | html! { }; 13 | html! {
    }; 14 | html! { }; 15 | html! {
    Invalid
    }; 16 | 17 | html! { }; 18 | html! { }; 19 | html! { }; 20 | html! { }; 21 | html! { }; 22 | html! {