Updated for 0.2.9, including a breaking change to Update

master
DavidOConnor 6 years ago
parent 1439b770a5
commit 6779329f21

@ -10,8 +10,8 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
seed = "^0.2.7" seed = "^0.2.9"
wasm-bindgen = "^0.2.33" wasm-bindgen = "^0.2.37"
web-sys = "^0.3.6" web-sys = "^0.3.6"
# For serialization, eg sending requests to a server. Otherwise, not required. # For serialization, eg sending requests to a server. Otherwise, not required.

@ -1,31 +1,31 @@
# Seed Quickstart # Seed Quickstart
**To get started:** **To get started:**
- Clone this repo - Clone this repo
- If you don't have Rust and wasm-bindgen installed, [Download it](https://www.rust-lang.org/tools/install), and run the following commands: - If you don't have Rust and wasm-bindgen installed, [Download it](https://www.rust-lang.org/tools/install), and run the following commands:
`rustup update` `rustup update`
`rustup target add wasm32-unknown-unknown` `rustup target add wasm32-unknown-unknown`
`cargo install wasm-bindgen-cli` `cargo install wasm-bindgen-cli`
If you run into errors while installing `wasm-bindgen-cli`, you may need to install a C++ If you run into errors while installing `wasm-bindgen-cli`, you may need to install a C++
build chain. On linux, run `sudo apt install build-essential`. On Windows, download and install build chain. On linux, run `sudo apt install build-essential`. On Windows, download and install
[Visual Studio 2017](https://visualstudio.microsoft.com/downloads/); when asked in the installer, [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/); when asked in the installer,
include the C++ workload. include the C++ workload.
- Run `build.sh` or `build.ps1`, then then start a dev server that supports WASM. - Run `build.sh` or `build.ps1`, then then start a dev server that supports WASM.
For example, with [Python](https://www.python.org/downloads/) installed, run `python serve.py`. For example, with [Python](https://www.python.org/downloads/) installed, run `python serve.py`.
(Linux users may need to run `python3 serve.py`.) (Linux users may need to run `python3 serve.py`.)
If you run into permission errors on `build.sh`, try this command If you run into permission errors on `build.sh`, try this command
to allow executing the file:`chmod +x build.sh`. If you run into persmission errors on `build.ps1`, open Powershell as an administrator, and enter this command: `Set-ExecutionPolicy RemoteSigned`. to allow executing the file:`chmod +x build.sh`. If you run into persmission errors on `build.ps1`, open Powershell as an administrator, and enter this command: `Set-ExecutionPolicy RemoteSigned`.
Once you rename the crate in `Cargo.toml` (The `name` field under `[Package]`), make the Once you rename the crate in `Cargo.toml` (The `name` field under `[Package]`), make the
following change: following change:
- Replace `appname` with your new name in either `build.sh`, or `build.ps1`, depending on your - Replace `appname` with your new name in either `build.sh`, or `build.ps1`, depending on your
operating system. operating system.

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

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cargo build --target wasm32-unknown-unknown cargo build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg --out-name package wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg --out-name package

@ -1,36 +1,36 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content=""> <meta name="description" content="">
<link rel="icon" type="image/png" href="/public/favicon.png"> <link rel="icon" type="image/png" href="/public/favicon.png">
<!--<link rel="stylesheet" type="text/css" href="/style.css">--> <!--<link rel="stylesheet" type="text/css" href="/style.css">-->
<title>A Title</title> <title>A Title</title>
</head> </head>
<body> <body>
<section id="app"></section> <section id="app"></section>
<script src='/pkg/package.js'></script> <script src='/pkg/package.js'></script>
<script> <script>
// the `wasm_bindgen` global is set to the exports of the Rust module // the `wasm_bindgen` global is set to the exports of the Rust module
const { render } = wasm_bindgen; const { render } = wasm_bindgen;
// we'll defer our execution until the wasm is ready to go // we'll defer our execution until the wasm is ready to go
function run() { function run() {
render(); render();
} }
// 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/package_bg.wasm') wasm_bindgen('/pkg/package_bg.wasm')
.then(run) .then(run)
.catch(console.error); .catch(console.error);
</script> </script>
</body> </body>
</html> </html>

@ -1,32 +1,32 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import http.server import http.server
import os import os
import socketserver import socketserver
import urllib import urllib
PORT = 8000 PORT = 8000
class Handler(http.server.SimpleHTTPRequestHandler): class Handler(http.server.SimpleHTTPRequestHandler):
# Allow SPA routing by redirecting subpaths. # Allow SPA routing by redirecting subpaths.
def do_GET(self): def do_GET(self):
urlparts = urllib.parse.urlparse(self.path) urlparts = urllib.parse.urlparse(self.path)
request_file_path = urlparts.path.strip('/') request_file_path = urlparts.path.strip('/')
if not os.path.exists(request_file_path): if not os.path.exists(request_file_path):
self.path = '/' self.path = '/'
return http.server.SimpleHTTPRequestHandler.do_GET(self) return http.server.SimpleHTTPRequestHandler.do_GET(self)
handler = Handler handler = Handler
# Add support for the WASM mime type. # Add support for the WASM mime type.
handler.extensions_map.update({ handler.extensions_map.update({
'.wasm': 'application/wasm', '.wasm': 'application/wasm',
}) })
socketserver.TCPServer.allow_reuse_address = True socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("", PORT), handler) as httpd: with socketserver.TCPServer(("", PORT), handler) as httpd:
httpd.allow_reuse_address = True httpd.allow_reuse_address = True
print("Serving at port", PORT) print("Serving at port", PORT)
httpd.serve_forever() httpd.serve_forever()

@ -26,7 +26,7 @@ enum Msg {
Increment, Increment,
} }
fn update(msg: Msg, model: Model) -> Update<Model> { fn update(msg: Msg, model: Model) -> Update<Msg, Model> {
match msg { match msg {
Msg::Increment => Render(Model {val: model.val + 1}) Msg::Increment => Render(Model {val: model.val + 1})
} }

Loading…
Cancel
Save