squark-stdweb

Crates.iosquark-stdweb
lib.rssquark-stdweb
version0.5.0
sourcesrc
created_at2018-03-29 13:21:34.359593
updated_at2018-04-10 13:28:41.462002
descriptionSquark runtime implemiontion for web browser with using stdweb
homepage
repository
max_upload_size
id58070
size14,496
Satoshi Amemiya (rail44)

documentation

README

squark

crates.io docs.rs

Virtual DOM implemention and application definition inspired from HyperApp.

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>
}

squark-stdweb

crates.io docs.rs

Squark 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.

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

Commit count: 0

cargo fmt