{"id":19670157,"url":"https://github.com/tostaylo/rust-fel","last_synced_at":"2025-02-27T04:42:48.025Z","repository":{"id":57665230,"uuid":"265436618","full_name":"tostaylo/rust-fel","owner":"tostaylo","description":"A front end library for rust wasm.","archived":false,"fork":false,"pushed_at":"2023-01-20T22:40:35.000Z","size":154,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T03:26:21.077Z","etag":null,"topics":["front-end-development","front-end-libraries","rust","rust-fel","rust-wasm"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/rust-fel","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/tostaylo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-20T03:14:05.000Z","updated_at":"2021-02-28T19:29:05.000Z","dependencies_parsed_at":"2023-02-12T06:15:57.882Z","dependency_job_id":null,"html_url":"https://github.com/tostaylo/rust-fel","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tostaylo%2Frust-fel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tostaylo%2Frust-fel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tostaylo%2Frust-fel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tostaylo%2Frust-fel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tostaylo","download_url":"https://codeload.github.com/tostaylo/rust-fel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240980792,"owners_count":19888343,"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":["front-end-development","front-end-libraries","rust","rust-fel","rust-wasm"],"created_at":"2024-11-11T17:04:46.060Z","updated_at":"2025-02-27T04:42:48.007Z","avatar_url":"https://github.com/tostaylo.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rust-fel\n\n[![Actions Status](https://github.com/tostaylo/rust-fel/workflows/Check%20Test%20Fmt%20Clippy/badge.svg)](https://github.com/tostaylo/rust-fel/actions) [![GitHub issues](https://img.shields.io/github/issues/tostaylo/rust-fel)](https://github.com/tostaylo/rust-fel/issues) [![GitHub license](https://img.shields.io/github/license/tostaylo/rust-fel)](https://github.com/tostaylo/rust-fel/blob/master/LICENSE.txt) [![Crates.io](https://img.shields.io/crates/v/rust-fel)](https://crates.io/crates/rust-fel) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/tostaylo/rust-fel)](https://github.com/tostaylo/rust-fel/releases/tag/v0.1.0) [![Crates.io](https://img.shields.io/badge/docs-rust--fel-red)](https://docs.rs/rust-fel/0.1.0/rust_fel/)\n\nAn experimental front end library which relies on [rustwasm](https://github.com/rustwasm).\n\nVery lightweight and does not support much of the [HTML Standard](https://html.spec.whatwg.org/). More work needs to be done to truly make this a viable option for creating client side front-ends with [rustwasm](https://github.com/rustwasm).\n\nA working example can be found here [rust-fel-example](https://github.com/tostaylo/rust-fel-example)\n\n## Features\n\n- State Management\n- [JSX](https://github.com/facebook/jsx) -like syntax\n- [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction) construction from a Virtual [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction).\n\n## Use\n\n```\nuse crate::main_component::Main;\nuse wasm_bindgen::prelude::_;\nextern crate rust_fel;\n\n// invoked when the wasm module is instantiated\n#[wasm_bindgen(start)]\npub fn main() -\u003e Result\u003c(), JsValue\u003e {\n  let main = Main::create();\n  let app = rust_fel::App::new(main);\n  app.mount(\"root\");\n\n  Ok(())\n}\n```\n\n### Examples\n\nA`rust_fel` [struct](https://doc.rust-lang.org/std/keyword.struct.html) component implements [rust_fel::Component](https://docs.rs/rust-fel/0.1.0/rust_fel/component/index.html)\n\n```\nuse crate::action::Action;\nuse crate::handle;\nuse crate::main_child::{ChildProps, MainChild};\nuse std::cell::RefCell;\nuse std::rc::Rc;\n\n#[derive(Debug, Default, Clone)]\npub struct MainState {\n  count: i32,\n}\n\npub enum Actions {\n  Counter(Action),\n}\n\n#[derive(Debug, Default, Clone)]\npub struct Main {\n  child: handle::Handle\u003cMainChild\u003e,\n  id: String,\n  state: MainState,\n  props: String,\n}\n\nimpl Main {\n  pub fn create() -\u003e handle::Handle\u003cSelf\u003e {\n    let main = Main {\n      id: \"main\".to_owned(),\n      state: MainState {\n      count: 0,\n      },\n      child: MainChild::create(),\n      ..Default::default()\n    };\n    handle::Handle(Rc::new(RefCell::new(main)))\n  }\n}\n\nimpl rust_fel::Component for handle::Handle\u003cMain\u003e {\n  type Properties = String;\n  type Message = Actions;\n  type State = MainState;\n\n  fn add_props(\u0026mut self, props: Self::Properties) {\n    self.0.borrow_mut().props = props;\n  }\n\n  fn reduce_state(\u0026mut self, message: Actions) {\n    match message {\n      Actions::Counter(Action::Increment) =\u003e self.0.borrow_mut().state.count += 100,\n      Actions::Counter(Action::Decrement) =\u003e self.0.borrow_mut().state.count -= 100,\n    }\n    rust_fel::re_render(self.render(), Some(self.0.borrow().id.clone()));\n  }\n\n  fn render(\u0026self) -\u003e rust_fel::Element {\n    let mut clone_for_props_closure = self.clone();\n    let mut clone_for_inc = self.clone();\n    let mut borrow = self.0.borrow_mut();\n    let state = borrow.state.clone();\n    let props_closure = Rc::new(RefCell::new(move || {\n      clone_for_props_closure.reduce_state(Actions::Counter(Action::Decrement))\n    }));\n\n    let child_props = ChildProps {\n      counter_props: state.count.to_string(),\n      closure: Some(props_closure),\n    };\n\n    borrow.child.add_props(child_props);\n\n    let main_text = rust_fel::html(format!(\n      \"\u003cspan | data-cy=main-text| \u003eMain {}\u003c/span\u003e\",\n      state.count.to_string()\n      ));\n\n    let inc_button = rust_fel::Element::new(\n      \"button\".to_owned(),\n      rust_fel::Props {\n        text: Some(\"Increment\".to_owned()),\n        on_click: Some(Box::new(move || {\n        clone_for_inc.reduce_state(Actions::Counter(Action::Increment))\n        })),\n        data_cy: Some(\"increment-main\".to_owned()),\n        children: Some(vec![inc_button_text]),\n        ..Default::default()\n        },\n      );\n\n    let main_el = rust_fel::Element::new(\n      \"div\".to_owned(),\n      rust_fel::Props {\n        class_name: Some(\"main-el\".to_owned()),\n        children: Some(vec![main_text, inc_button, input_wrapper]),\n        ..Default::default()\n        },\n      );\n\n    let child_wrapper = rust_fel::Element::new(\n      \"div\".to_owned(),\n      rust_fel::Props {\n        class_name: Some(\"child-wrapper\".to_owned()),\n        children: Some(vec![borrow.child.render()]),\n        ..Default::default()\n        },\n      );\n\n    rust_fel::Element::new(\n      \"div\".to_owned(),\n      rust_fel::Props {\n        id: Some(borrow.id.clone()),\n        class_name: Some(\"main\".to_owned()),\n        children: Some(vec![main_el, child_wrapper]),\n        ..Default::default()\n        },\n      )\n    }\n}\n```\n\nA `rust_fel` functional component with [rust_fel::html](https://docs.rs/rust-fel/0.1.0/rust_fel/rsx/fn.html.html).\n\n```\n  pub fn theme_switcher(on_click: rust_fel::ClosureProp, title: String) -\u003e rust_fel::Element {\n    let text = rust_fel::html(format!(\n      \"\u003cspan |class=theme-switcher-text|\u003e{}\u003c/span\u003e\",\n      title\n  ));\n\n  let theme_button = rust_fel::Element::new(\n    \"button\".to_owned(),\n    rust_fel::Props {\n      on_click: Some(on_click),\n      type_attr: Some(\"button\".to_owned()),\n      class_name: Some(\"theme-switcher-button\".to_owned()),\n      children: Some(vec![text]),\n      data_cy: Some(title),\n      ..Default::default()\n      },\n    );\n\n  rust_fel::Element::new(\n    \"li\".to_owned(),\n    rust_fel::Props {\n      children: Some(vec![theme_button]),\n      ..Default::default()\n      },\n    )\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftostaylo%2Frust-fel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftostaylo%2Frust-fel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftostaylo%2Frust-fel/lists"}