Minor updates

master
DavidOConnor 6 years ago
parent 907f5c2442
commit 6f14f54e22

3
.gitignore vendored

@ -1,3 +1,6 @@
/target /target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
**/pkg/*
**/.wasm

@ -1,7 +1,7 @@
[package] [package]
name = "appname" name = "appname"
version = "0.1.0" version = "0.1.0"
authors = ["DavidOConnor <david.alan.oconnor@gmail.com>"] authors = ["Your Name <email@address.com>"]
edition = "2018" edition = "2018"
@ -9,5 +9,11 @@ edition = "2018"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
seed = "^0.1.0"
wasm-bindgen = "^0.2.28" 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"

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

@ -0,0 +1,2 @@
cargo build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg

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

@ -8,9 +8,7 @@
<link rel="icon" type="image/png" href="./public/favicon.png"> <link rel="icon" type="image/png" href="./public/favicon.png">
<link href="https://fonts.googleapis.com/css?family=Karla" rel="stylesheet"> <!--<link rel="stylesheet" type="text/css" href="./style.css">-->
<!--<link rel="stylesheet" type="text/css" href="./public/style.css">-->
<title>A Title</title> <title>A Title</title>
@ -42,7 +40,7 @@
} }
// here we tell bindgen the path to the wasm file so it can run // 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 // initialization and return to us a promise when it's done
wasm_bindgen('./pkg/appname.wasm') wasm_bindgen('./pkg/appname_bg.wasm')
.then(run) .then(run)
.catch(console.error); .catch(console.error);
</script> </script>

@ -1,19 +1,16 @@
#[macro_use]
extern crate seed;
use seed::prelude::*;
use wasm_bindgen::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 // Model
#[derive(Clone, Debug)] // todo #[derive(Clone)]
struct Model { struct Model {
pub val: i32, pub val: i32,
} }
// Setup a default here, for initialization later.
impl Default for Model { impl Default for Model {
fn default() -> Self { fn default() -> Self {
Self { Self {
@ -22,35 +19,30 @@ impl Default for Model {
} }
} }
// Update // Update
#[derive(Clone)]
enum Msg { enum Msg {
Increment, Increment,
} }
//fn update(msg: &Msg, model: Rc<Model>) -> Model { fn update(msg: &Msg, model: &Model) -> Model {
fn update(msg: &Msg, model: Rc<RefCell<Model>>) -> Model {
// todo msg probably doesn't need to be a ref.
// let model2 = model.clone(); // todo deal with this.
match msg { match msg {
&Msg::Increment => { Msg::Increment => {
// Model {clicks: model.clicks + 1, ..model.unwrap()} Model {val: model.val + 1}
Model {clicks: model.borrow().clicks + 1, what_we_count: String::from("test")}
}, },
} }
} }
// View // View
// Top-level component we pass to the virtual dom. Must accept the model as its only argument. fn main_comp(model: &Model) -> El<Msg> {
fn comp(model: &Model) -> El<Msg> { div![ "Hello, World" ]
!div[]]
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn render() -> Result<(), JsValue> { pub fn render() {
let model = Model::default(); seed::vdom::run(Model::default(), update, main_comp, "main");
let mut app = App::new(model, update, comp, "main");
app.mount()
} }
Loading…
Cancel
Save