From 907f5c244281007f91c04ce6eebe56fa6b501ebc Mon Sep 17 00:00:00 2001 From: DavidOConnor Date: Sat, 1 Dec 2018 11:24:07 -0500 Subject: [PATCH] first commit --- .gitignore | 3 +++ Cargo.toml | 13 +++++++++++++ index.html | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 index.html create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6936990 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e87cc46 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "appname" +version = "0.1.0" +authors = ["DavidOConnor "] +edition = "2018" + + +[lib] +crate-type = ["cdylib"] + +[dependencies] +wasm-bindgen = "^0.2.28" +rebar = "^0.1.0" diff --git a/index.html b/index.html new file mode 100644 index 0000000..97813c6 --- /dev/null +++ b/index.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + A Title + + + +
+ + + + + + + + + diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b28d7eb --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,56 @@ +use wasm_bindgen::prelude::*; + +// This prelude is the equivalent of the following imports: +// use rebar::dom_types::{El, Style, Attrs, Tag, Event, Events, UpdateEl}; +// use rebar::vdom::App; +use crate::prelude::*; + + +// Model + +#[derive(Clone, Debug)] // todo +struct Model { + pub val: i32, +} + +// Setup a default here, for initialization later. +impl Default for Model { + fn default() -> Self { + Self { + val: 0, + } + } +} + +// Update + +enum Msg { + Increment, +} + +//fn update(msg: &Msg, model: Rc) -> Model { +fn update(msg: &Msg, model: Rc>) -> Model { + // todo msg probably doesn't need to be a ref. +// let model2 = model.clone(); // todo deal with this. + match msg { + &Msg::Increment => { +// Model {clicks: model.clicks + 1, ..model.unwrap()} + Model {clicks: model.borrow().clicks + 1, what_we_count: String::from("test")} + }, + } +} + +// View + +// Top-level component we pass to the virtual dom. Must accept the model as its only argument. +fn comp(model: &Model) -> El { + !div[]] +} + +#[wasm_bindgen] +pub fn render() -> Result<(), JsValue> { + let model = Model::default(); + + let mut app = App::new(model, update, comp, "main"); + app.mount() +} \ No newline at end of file