squark-macros 0.5.1

Macros like JSX to help building Squark application
docs.rs failed to build squark-macros-0.5.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: squark-macros-0.7.0

squark

crates.io docs.rs

Virtual DOM implemention and definitions of Application and Runtime.

Fertures

This repository includes

  • Pure Rust virtual DOM implemention
  • Definition of application inspired from HyperApp
  • Definition of runtime to handle diffirence of virtual DOM
  • Runtime implementions for several platforms
    • For web browser by using stdweb.
    • Server side rendering within Rustic world (now working)
  • Macros like a JSX to help writing view

Currently, we depend on nightly channel

squark-macros

crates.io docs.rs

Crate that providing JSX like macro by proc_marco and pest parser.

Syntax

view! {
    <button class="some-class" onclick={ |_| { Some(Action::Submit) }>
        Button!
    </button>
}

We can generate native Rust expression at compile-time.

squark-stdweb

crates.io docs.rs

Runtime implemention for web browser with usinng stdweb.

Here is full example of counter app!

#![feature(proc_macro)]

extern crate squark;
extern crate squark_macros;
extern crate squark_stdweb;
extern crate stdweb;

use stdweb::traits::*;
use stdweb::web::document;
use squark::{App, Runtime, View};
use squark_stdweb::StdwebRuntime;
use squark_macros::view;

#[derive(Clone, Debug, PartialEq)]
struct State {
    count: isize,
}

impl State {
    pub fn new() -> State {
        State { count: 0 }
    }
}

#[derive(Clone, Debug)]
enum Action {
    ChangeCount(isize),
}

#[derive(Clone, Debug)]
struct CounterApp;
impl App for CounterApp {
    type State = State;
    type Action = Action;

    fn reducer(mut state: State, action: Action) -> State {
        match action {
            Action::ChangeCount(c) => {
                state.count = c;
            }
        };
        state
    }

    fn view(state: State) -> View<Action> {
        let count = state.count.clone();
        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>
        }
    }
}

fn main() {
    stdweb::initialize();
    StdwebRuntime::<CounterApp>::new(
        document().query_selector("body").unwrap().unwrap(),
        State::new(),
    ).run();
    stdweb::event_loop();
}

Project dir is located at examples/counter. You can try it with cargo-web.

# on ./examples/counter
cargo install cargo-web
cargo toolchain install nightly-2017-12-01
cargo +nightly-2017-12-01 web start --target=wasm32-unknown-unknown

There is also available TodoMVC example at examples/todomvc and working on https://rail44.github.io/squark/.