Bladeren bron

Initial commit

master
Dylan Baker 8 maanden geleden
commit
fbe83e2beb
8 gewijzigde bestanden met toevoegingen van 159 en 0 verwijderingen
  1. 3
    0
      .gitignore
  2. 18
    0
      Cargo.toml
  3. 14
    0
      bootstrap.sh
  4. 17
    0
      index.html
  5. 79
    0
      src/lib.rs
  6. 10
    0
      start-debug-mode.sh
  7. 9
    0
      start-profiling.sh
  8. 9
    0
      start-release-mode.sh

+ 3
- 0
.gitignore Bestand weergeven

@@ -0,0 +1,3 @@
1
+target/
2
+**/*.rs.bk
3
+*.lock

+ 18
- 0
Cargo.toml Bestand weergeven

@@ -0,0 +1,18 @@
1
+[package]
2
+name = "domain-hacks"
3
+version = "0.1.0"
4
+authors = [ "Dylan Baker <dylan@simulacrum.party>" ]
5
+license = "MIT"
6
+edition = "2018"
7
+
8
+[lib]
9
+crate-type = ["cdylib"]
10
+
11
+[dependencies]
12
+console_error_panic_hook = "0.1"
13
+console_log = { version = "0.2", features = ["color"] }
14
+log = "0.4"
15
+sauron = "0.31.2"
16
+
17
+[features]
18
+with-measure = ["sauron/with-measure"]

+ 14
- 0
bootstrap.sh Bestand weergeven

@@ -0,0 +1,14 @@
1
+#!/bin/bash
2
+
3
+set -v
4
+
5
+if ! type wasm-pack > /dev/null; then
6
+    echo "wasm-pack is not installed"
7
+    cargo install wasm-pack
8
+fi
9
+
10
+if ! type basic-http-server > /dev/null; then
11
+    echo "basic-http-server is not installed"
12
+    cargo install basic-http-server
13
+fi
14
+

+ 17
- 0
index.html Bestand weergeven

@@ -0,0 +1,17 @@
1
+<html>
2
+  <head>
3
+    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
4
+    <title>Minimal sauron app</title>
5
+    <style type="text/css">
6
+        body {
7
+            font-family: "Fira Sans", "Courier New", Courier,"Lucida Sans Typewriter","Lucida Typewriter",monospace;
8
+        }
9
+    </style>
10
+  </head>
11
+  <body>
12
+    <script type="module">
13
+      import init from './pkg/domain_hacks.js';
14
+      init().catch(console.error);
15
+    </script>
16
+  </body>
17
+</html>

+ 79
- 0
src/lib.rs Bestand weergeven

@@ -0,0 +1,79 @@
1
+#![deny(warnings)]
2
+use log::trace;
3
+use sauron::html::attributes::{attr, class, id, key, type_, value};
4
+use sauron::html::events::on_click;
5
+use sauron::html::{div, h1, input, text};
6
+use sauron::prelude::*;
7
+use sauron::{Cmd, Component, Node, Program};
8
+
9
+pub enum Msg {
10
+    Click,
11
+}
12
+
13
+pub struct App {
14
+    click_count: u32,
15
+}
16
+
17
+impl App {
18
+    pub fn new() -> Self {
19
+        App { click_count: 0 }
20
+    }
21
+}
22
+
23
+impl Component<Msg> for App {
24
+    fn view(&self) -> Node<Msg> {
25
+        sauron::html::main(
26
+            vec![],
27
+            vec![
28
+                h1(vec![], vec![text("Minimal example")]),
29
+                div(
30
+                    vec![
31
+                        class("some-class"),
32
+                        id("some-id"),
33
+                        attr("data-id", 1),
34
+                    ],
35
+                    vec![
36
+                        input(
37
+                            vec![
38
+                                class("client"),
39
+                                type_("button"),
40
+                                value("Click me!"),
41
+                                key(1),
42
+                                on_click(|_| {
43
+                                    trace!("Button is clicked");
44
+                                    Msg::Click
45
+                                }),
46
+                            ],
47
+                            vec![],
48
+                        ),
49
+                        div(
50
+                            vec![],
51
+                            vec![text(format!(
52
+                                "Clicked: {}",
53
+                                self.click_count
54
+                            ))],
55
+                        ),
56
+                        input(
57
+                            vec![type_("text"), value(self.click_count)],
58
+                            vec![],
59
+                        ),
60
+                    ],
61
+                ),
62
+            ],
63
+        )
64
+    }
65
+
66
+    fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {
67
+        match msg {
68
+            Msg::Click => self.click_count += 1,
69
+        }
70
+        Cmd::none()
71
+    }
72
+}
73
+
74
+#[wasm_bindgen(start)]
75
+pub fn main() {
76
+    console_log::init_with_level(log::Level::Trace).unwrap();
77
+    console_error_panic_hook::set_once();
78
+    Program::mount_to_body(App::new());
79
+}

+ 10
- 0
start-debug-mode.sh Bestand weergeven

@@ -0,0 +1,10 @@
1
+#!/bin/bash
2
+
3
+set -v
4
+
5
+. ./bootstrap.sh
6
+
7
+
8
+wasm-pack build --target web --dev -- --features "with-measure"
9
+
10
+basic-http-server ./ -a 0.0.0.0:4001

+ 9
- 0
start-profiling.sh Bestand weergeven

@@ -0,0 +1,9 @@
1
+#!/bin/bash
2
+
3
+set -v
4
+
5
+. ./bootstrap.sh
6
+
7
+wasm-pack build --target web --profiling
8
+
9
+basic-http-server ./ -a 0.0.0.0:4001

+ 9
- 0
start-release-mode.sh Bestand weergeven

@@ -0,0 +1,9 @@
1
+#!/bin/bash
2
+
3
+set -v
4
+
5
+. ./bootstrap.sh
6
+
7
+wasm-pack build --target web --release
8
+
9
+basic-http-server ./ -a 0.0.0.0:4001

Laden…
Annuleren
Opslaan