{"id":19094887,"url":"https://github.com/zahash/reactivate","last_synced_at":"2025-04-30T14:07:42.860Z","repository":{"id":180955166,"uuid":"665972798","full_name":"zahash/reactivate","owner":"zahash","description":"Thread Safe Reactive Data Structure. Made with ❤️ for 🦀","archived":false,"fork":false,"pushed_at":"2024-03-25T17:58:30.000Z","size":51,"stargazers_count":41,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T00:48:39.267Z","etag":null,"topics":["observer-pattern","reactive","reactive-programming","rust","thread","threads","threadsafe"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/reactivate","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zahash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-13T12:15:32.000Z","updated_at":"2025-03-06T03:20:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"e33f7e7d-9709-4881-b0e2-f50501dd4f30","html_url":"https://github.com/zahash/reactivate","commit_stats":null,"previous_names":["zahash/reactive","zahash/reactivate","zahash/reactivx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahash%2Freactivate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahash%2Freactivate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahash%2Freactivate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahash%2Freactivate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zahash","download_url":"https://codeload.github.com/zahash/reactivate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251716705,"owners_count":21632174,"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":["observer-pattern","reactive","reactive-programming","rust","thread","threads","threadsafe"],"created_at":"2024-11-09T03:31:57.210Z","updated_at":"2025-04-30T14:07:42.812Z","avatar_url":"https://github.com/zahash.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cpre\u003e\n██████╗ ███████╗ █████╗  ██████╗████████╗██╗██╗   ██╗ █████╗ ████████╗███████╗\n██╔══██╗██╔════╝██╔══██╗██╔════╝╚══██╔══╝██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝\n██████╔╝█████╗  ███████║██║        ██║   ██║██║   ██║███████║   ██║   █████╗  \n██╔══██╗██╔══╝  ██╔══██║██║        ██║   ██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  \n██║  ██║███████╗██║  ██║╚██████╗   ██║   ██║ ╚████╔╝ ██║  ██║   ██║   ███████╗\n╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝   ╚═╝   ╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝\n------------------------------------------------------------------------------\nThread Safe Reactive Data Structure. Made with ❤️ for 🦀\n\u003c/pre\u003e\n\n[![Crates.io](https://img.shields.io/crates/v/reactivate.svg)](https://crates.io/crates/reactivate)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u003c/div\u003e\n\n## 🚀 Installation\n\ninclude it in your `Cargo.toml` under `[dependencies]`\n\n```toml\nreactivate = { version = \"*\", features = [\"threadsafe\"] }\n```\n\n## 🧑‍💻 Usage examples\n\n### 🏗️ Construction\n\n```rust\nuse reactivate::Reactive;\n\nfn main() {\n    let r = Reactive::new(10);\n\n    println!(\"{:?}\", r); // Reactive(10)\n    println!(\"{:?}\", r.value()); // 10\n}\n```\n\n### 🔥 Derive\n\n```rust\nuse reactivate::Reactive;\n\nfn main() {\n    let r = Reactive::new(10);\n    let d = r.derive(|val| val + 5);\n\n    println!(\"{:?}\", r); // Reactive(10)\n    println!(\"{:?}\", d); // Reactive(15)\n}\n```\n\n### ✨ Update\n\n```rust\nuse reactivate::Reactive;\n\nfn main() {\n    let r = Reactive::new(10);\n    let d = r.derive(|val| val + 5);\n\n    r.update(|_| 20);\n\n    println!(\"{:?}\", r); // Reactive(20)\n    println!(\"{:?}\", d); // Reactive(25)\n}\n```\n\n### ⚡ Update Inplace\n\n```rust\nuse reactivate::Reactive;\n\nfn main() {\n    let r = Reactive::new(vec![1, 2, 3]);\n    let d = r.derive(|nums| nums.iter().sum::\u003ci32\u003e());\n\n    r.update_inplace(|nums| {\n        nums.push(4);\n        nums.push(5);\n        nums.push(6);\n    });\n\n    println!(\"{:?}\", r); // Reactive([1, 2, 3, 4, 5, 6])\n    println!(\"{:?}\", d); // Reactive(21)\n}\n```\n\n### 🤝 Merge and Derive\n\n```rust\nuse reactivate::{Merge, Reactive};\n\nfn main() {\n    let a = Reactive::new(String::from(\"hazash\"));\n    let b = Reactive::new(0);\n    let d = (\u0026a, \u0026b)\n        .merge()\n        .derive(|(a_val, b_val)| a_val.len() + b_val);\n\n    println!(\"{:?}\", a); // Reactive(\"hazash\")\n    println!(\"{:?}\", b); // Reactive(0)\n    println!(\"{:?}\", d); // Reactive(6)\n\n    b.update(|_| 5);\n\n    println!(\"{:?}\", a); // Reactive(\"hazash\")\n    println!(\"{:?}\", b); // Reactive(5)\n    println!(\"{:?}\", d); // Reactive(11)\n\n\n    a.update(|_| String::from(\"mouse\"));\n\n    println!(\"{:?}\", a); // Reactive(\"mouse\")\n    println!(\"{:?}\", b); // Reactive(5)\n    println!(\"{:?}\", d); // Reactive(10)\n}\n```\n\n### 👀 Add Observers\n\n```rust\nuse reactivate::Reactive;\nuse std::sync::{Arc, Mutex};\n\nfn main() {\n    let r: Reactive\u003cString\u003e = Reactive::default();\n\n    // Arc\u003cMutex\u003cT\u003e\u003e is used to make the vector thread safe\n    // because Reactive as a whole must be thread safe\n    let changes: Arc\u003cMutex\u003cVec\u003cString\u003e\u003e\u003e = Default::default();\n\n    r.add_observer({\n        let changes = changes.clone();\n        move |val| changes.lock().unwrap().push(val.clone())\n    });\n\n    r.update(|_| String::from(\"a\"));\n    r.update_inplace(|s| {\n        s.push('b');\n    });\n\n    println!(\"{:?}\", r); // Reactive(\"ab\")\n    println!(\"{:?}\", changes.lock().unwrap().clone()); // [\"a\", \"ab\"]\n}\n```\n\n### 🧵 With Threads (features = [\"threadsafe\"])\n\n```rust\nuse reactivate::Reactive;\nuse std::{thread, time::Duration};\n\nfn main() {\n    let r: Reactive\u003cString\u003e = Reactive::default();\n    let d = r.derive(|s| s.len());\n\n    let handle = thread::spawn({\n        let r = r.clone();\n\n        move || {\n            for _ in 0..10 {\n                r.update_inplace(|s| s.push('a'));\n                thread::sleep(Duration::from_millis(1));\n            }\n        }\n    });\n\n    for _ in 0..10 {\n        r.update_inplace(|s| s.push('b'));\n        thread::sleep(Duration::from_millis(1));\n    }\n\n    handle.join().unwrap();\n\n    println!(\"{:?}\", r); // Reactive(\"babababababababababa\")\n    println!(\"{:?}\", d); // Reactive(20)\n}\n```\n\n## 🌟 Connect with Us\n\nM. Zahash – zahash.z@gmail.com\n\nDistributed under the MIT license. See `LICENSE` for more information.\n\n[https://github.com/zahash/](https://github.com/zahash/)\n\n## 🤝 Contribute to Reactivate!\n\n1. Fork it (\u003chttps://github.com/zahash/reactivate/fork\u003e)\n2. Create your feature branch (`git checkout -b feature/fooBar`)\n3. Commit your changes (`git commit -am 'Add some fooBar'`)\n4. Push to the branch (`git push origin feature/fooBar`)\n5. Create a new Pull Request\n\n## ❤️ Show Some Love!\n\nIf you find Reactivate helpful and enjoy using it, consider giving it a [⭐ on GitHub!](https://github.com/zahash/reactivate/stargazers) Your star is a gesture of appreciation and encouragement for the continuous improvement of Reactivate.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzahash%2Freactivate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzahash%2Freactivate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzahash%2Freactivate/lists"}