Hirola is an opinionated web framework for that is focused on simplicity and predicatability.
lib.rs ```rust use hirola::prelude::*; use std::sync::Arc;
struct Count {
counter: Reactive
impl Count { fn increment(&self) { let count = &self.counter.clone(); count.replace_with(|x| *x + 1); }
fn decrement(&self) {
let count = &self.counter.clone();
count.replace_with(|x| *x - 1);
}
}
impl State for Count {}
struct Counter;
impl Component
pub fn main() -> Result<(), JsValue> { #[cfg(debugassertions)] consoleerrorpanichook::set_once(); hirola::mount(&mut Counter, None); Ok(()) }
```
public/index.html
html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hirola Counter</title>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<script src="js/index.js"></script>
</body>
</html>
In Cargo.toml, specify the crate-type to be cdylib
```toml
[package] name = "counter" version = "0.1.0" edition = "2018"
[lib] crate-type = ["cdylib"]
[dependencies] hirola = "0.1.0" consoleerrorpanichook = "0.1" log = "0.4" consolelog = "0.2" ```
package.json ```json { "private": true, "author": "@geofmureithi", "name": "counter", "version": "0.1.0", "scripts": { "build": "rimraf dist/js && rollup --config", "start": "rimraf dist/js && rollup --config --watch" }, "devDependencies": { "@wasm-tool/rollup-plugin-rust": "^1.0.0", "rimraf": "^3.0.2", "rollup": "^1.31.0", "rollup-plugin-livereload": "^1.2.0", "rollup-plugin-serve": "^1.0.1" } }
rollup.config.js
js
import rust from "@wasm-tool/rollup-plugin-rust";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
const iswatch = !!process.env.ROLLUPWATCH;
export default { input: { index: "./Cargo.toml", }, output: { dir: "public/js", format: "iife", sourcemap: true, }, plugins: [ rust({ serverPath: "js/", debug: false, }),
is_watch && serve({
contentBase: "public",
open: true,
}),
is_watch && livereload("public"),
],
}; ```
Start using
sh
$> yarn start
Build using
sh
$> yarn build
You need need to have rust
and cargo
installed.
For the counter example, you need node.js
and npm
installed.
Note:
The above example doesnt work yet.. The counter example in the
cargo web
doesnt work possibly because of wasm-bindgen
License: MIT