Rust frontend framework, for web browser and more.
Currently, we depend on nightly
channel
squark
crate has no dependency for specific platformCore crate.
It provides macro like JSX for helping writing view.
Very thanks to pest parser.
view! {
<button class="some-class" onclick={ |_| Some(Action::Submit) }>
Button!
</button>
}
We can generate native Rust expression at compile-time.
Runtime implemention for web browser with usinng wasm-bindgen.
Here is full example of counter app!
```rust
extern crate squark; extern crate squarkmacros; extern crate squarkweb; extern crate wasmbindgen; extern crate websys;
use squark::{App, Runtime, View, Task}; use squarkmacros::view; use squarkweb::WebRuntime; use wasmbindgen::prelude::*; use websys::window;
struct State { count: isize, }
impl State { pub fn new() -> State { State { count: 0 } } }
enum Action { ChangeCount(isize), }
struct CounterApp; impl App for CounterApp { type State = State; type Action = Action;
fn reducer(&self, mut state: State, action: Action) -> (State, Task<Action>) {
match action {
Action::ChangeCount(c) => {
state.count = c;
}
};
(state, Task::empty())
}
fn view(&self, state: State) -> View<Action> {
let count = state.count;
view! {
<div>
{ count.to_string() }
<button onclick={ move |_| Some(Action::ChangeCount(count.clone() + 1)) }>
increment
</button>
<button onclick={ move |_| Some(Action::ChangeCount(count - 1)) }>
decrement
</button>
</div>
}
}
}
impl Default for CounterApp { fn default() -> CounterApp { CounterApp } }
pub fn run() {
WebRuntime::
Project dir is located at examples/counter.
There are some other examples available on examples, most of them use rust-webpack-template.
TodoMVC is working on https://rail44.github.io/squark/.