diff --git a/.gitignore b/.gitignore index 6936990..6c1daf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /target **/*.rs.bk Cargo.lock + +**/pkg/* +**/.wasm \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index e87cc46..8682a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "appname" version = "0.1.0" -authors = ["DavidOConnor "] +authors = ["Your Name "] edition = "2018" @@ -9,5 +9,11 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] +seed = "^0.1.0" wasm-bindgen = "^0.2.28" -rebar = "^0.1.0" +web-sys = "^0.3.6" + +# For serialization, eg sending requests to a server. Otherwise, not required. +serde = "^1.0.80" +serde_derive = "^1.0.80" +serde_json = "1.0.33" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfee824 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Rebar Quickstart + +To get started with Rebar, clone this repo, and make the following changes: + +-Rename your crate in `Cargo.toml` (The `name` field under `[Package]`) + +- Replace both occurances of `appname` (`/appname.js` and `/appname.wasm`) in `index.html` with your +crate's name + +- Make the same replacement in either `build.sh`, or `build.ps1`, depending on your +operating system (`.sh` for Linux, `.ps` for Windows). You may delete the other one + +You may also wish to replace the contents of this file. \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..aec6011 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,2 @@ +cargo build --target wasm32-unknown-unknown +wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..57cc1b7 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cargo build --target wasm32-unknown-unknown +wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg \ No newline at end of file diff --git a/index.html b/index.html index 97813c6..57893ea 100644 --- a/index.html +++ b/index.html @@ -8,9 +8,7 @@ - - - + A Title @@ -42,7 +40,7 @@ } // here we tell bindgen the path to the wasm file so it can run // initialization and return to us a promise when it's done - wasm_bindgen('./pkg/appname.wasm') + wasm_bindgen('./pkg/appname_bg.wasm') .then(run) .catch(console.error); diff --git a/src/lib.rs b/src/lib.rs index b28d7eb..b920ef6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,19 +1,16 @@ +#[macro_use] +extern crate seed; +use seed::prelude::*; 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 +#[derive(Clone)] struct Model { pub val: i32, } -// Setup a default here, for initialization later. impl Default for Model { fn default() -> Self { Self { @@ -22,35 +19,30 @@ impl Default for Model { } } + // Update +#[derive(Clone)] 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. +fn update(msg: &Msg, model: &Model) -> Model { match msg { - &Msg::Increment => { -// Model {clicks: model.clicks + 1, ..model.unwrap()} - Model {clicks: model.borrow().clicks + 1, what_we_count: String::from("test")} + Msg::Increment => { + Model {val: model.val + 1} }, } } + // View -// Top-level component we pass to the virtual dom. Must accept the model as its only argument. -fn comp(model: &Model) -> El { - !div[]] +fn main_comp(model: &Model) -> El { + div![ "Hello, World" ] } #[wasm_bindgen] -pub fn render() -> Result<(), JsValue> { - let model = Model::default(); - - let mut app = App::new(model, update, comp, "main"); - app.mount() +pub fn render() { + seed::vdom::run(Model::default(), update, main_comp, "main"); } \ No newline at end of file