{"id":21296147,"url":"https://github.com/dukeferdinand/yew-reactive-state","last_synced_at":"2026-05-19T11:05:37.382Z","repository":{"id":41685489,"uuid":"250716760","full_name":"DukeFerdinand/yew-reactive-state","owner":"DukeFerdinand","description":"An example project on using `Arc` based state in Yew with the reactive library `futures_signals`","archived":false,"fork":false,"pushed_at":"2023-01-07T16:29:08.000Z","size":1353,"stargazers_count":2,"open_issues_count":22,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-22T07:16:41.882Z","etag":null,"topics":["rust","state-management","wasm","yew"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DukeFerdinand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-28T04:50:15.000Z","updated_at":"2020-05-12T06:33:14.000Z","dependencies_parsed_at":"2023-02-07T15:46:44.236Z","dependency_job_id":null,"html_url":"https://github.com/DukeFerdinand/yew-reactive-state","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DukeFerdinand%2Fyew-reactive-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DukeFerdinand%2Fyew-reactive-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DukeFerdinand%2Fyew-reactive-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DukeFerdinand%2Fyew-reactive-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DukeFerdinand","download_url":"https://codeload.github.com/DukeFerdinand/yew-reactive-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243763236,"owners_count":20344189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","state-management","wasm","yew"],"created_at":"2024-11-21T14:20:22.841Z","updated_at":"2026-05-19T11:05:32.343Z","avatar_url":"https://github.com/DukeFerdinand.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## How to Run\n\nMake sure you're using the nightly rust in this project:\n\n```bash\n$ rustup override set nightly\n```\n\nInstall all JS build dependencies with npm/yarn:\n\n```sh\n$ npm install # or yarn install\n```\n\nThen run in your terminal:\n\n```sh\n$ npm run start:dev # yarn start:dev\n```\n\nThen you can visit http://localhost:8000 in your favorite browser :)\n\n## About\n\nThe purpose of this project is to show how to effectively pass state around your application in a reactive way, without throwing away the convenience of yew's `Agent` system.\n\nYou can use this as a minimal template for any of your web applications. The base for the state system here is a `yew` Agent and the `Mutable` wrapper from `futures_signals`.\n\nThe flow is as follows:\n\n- App Component (or other higher up component) makes first connection with `Store` Agent.\n- `Store` agent is created, instantiates `State` object with `Mutable` field(s).\n- Store sends `StateInstance(State)` back to `App` (or other connected components on connect)\n- Component can then subscribe to any updates it cares about\n\nHere's an example on how to subscribe to updates on a `String` field:\n\n```rust\nimpl App {\n    fn register_state_handlers(\u0026self) {\n        let callback = self.link.callback(|ip| Msg::SetIp(ip));\n        let state = self.state_ref.as_ref().unwrap();\n\n        // use signal() for copy-able types\n        // signal_cloned() for things like Strings that can't be copied\n        let handler = state.ip.signal_cloned().for_each(move |u| {\n            info!(\"{:?}\", u); // from log crate\n            callback.emit(u);\n            ready(()) // from futures crate\n        });\n\n        // for_each converts the signals into futures\n        // so you'll need to spawn the futures locally\n        spawn_local(handler); // from wasm_bindgen_futures\n    }\n}\n\n// ... rest of your component implementation\n```\n\nThe `State` object in this case would look something like this:\n\n```rust\nstruct State {\n  ip: Mutable\u003cOption\u003cString\u003e\u003e\n}\n```\n\n## Global Updates\n\nI've added the `Subscriber` component along with add and remove buttons in `App` just to show you how the global state will be retained as long as a connection to `Store` is alive (usually in `App` or your highest rendered component, even if `App` doesn't need to use anything in `State`).\n\nUnfortunately due to the nature of Rust's memory management, you'll need to keep a reference to your `Store` connection around in each component in order to start up your state subscriptions. I haven't come up with any ways around this yet, but please feel free to make a PR/issue regarding this :)\n\n### For More info on `futures_signals`\n\nYou can use the tutorial for the library [here](https://docs.rs/futures-signals/0.3.15/futures_signals/tutorial/index.html).\n\nThere's a lot more to it than I've included, like `MutableVec` as a subscribable `Vec` type with its own set of update filters. You should check it out! :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdukeferdinand%2Fyew-reactive-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdukeferdinand%2Fyew-reactive-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdukeferdinand%2Fyew-reactive-state/lists"}