Minor updates

master
DavidOConnor 6 years ago
parent 907f5c2442
commit 6f14f54e22

3
.gitignore vendored

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

@ -1,7 +1,7 @@
[package]
name = "appname"
version = "0.1.0"
authors = ["DavidOConnor <david.alan.oconnor@gmail.com>"]
authors = ["Your Name <email@address.com>"]
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"

@ -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 href="https://fonts.googleapis.com/css?family=Karla" rel="stylesheet">
<!--<link rel="stylesheet" type="text/css" href="./public/style.css">-->
<!--<link rel="stylesheet" type="text/css" href="./style.css">-->
<title>A Title</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);
</script>

@ -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>) -> 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.
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<Msg> {
!div[]]
fn main_comp(model: &Model) -> El<Msg> {
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");
}
Loading…
Cancel
Save