Clean up the yew example

This commit is contained in:
Bradlee Speice 2020-07-24 14:52:42 -04:00
parent bbc881c0e1
commit 83d5e098d9
27 changed files with 3270 additions and 13831 deletions

View File

@ -9,9 +9,15 @@ It's 2020, and a lot has changed.
- The previous [`percy`](https://github.com/chinedufn/percy) example has been removed. While work - The previous [`percy`](https://github.com/chinedufn/percy) example has been removed. While work
continues on the project, there haven't been any releases. continues on the project, there haven't been any releases.
- `binaryen` has been removed. - `binaryen` has been removed.
- The "minimal" (wasm-bindgen only) example has been removed. It's easy enough to start with one of
the framework examples and remove it if truly desired.
- A new framework [`seed`](https://github.com/seed-rs/seed) as been added as an example. - A new framework [`seed`](https://github.com/seed-rs/seed) as been added as an example.
- The `stdweb` example has been freshened up: - The `stdweb` example has been freshened up:
- It actually runs now.
- Use `#[wasm_bindgen(start)]` to remove the app loader script - Use `#[wasm_bindgen(start)]` to remove the app loader script
- Don't use `innerHTML`, just set the text content directly. - Don't use `innerHTML`, just set the text content directly.
- The `yew` example has been freshened up:
- All the changes that were made to `stdweb`; actually runs, removed app loader
- Uses an ever-so-slightly more realistic counter example.
Each app is a starter example, and can be run with `yarn install && yarn start`. Each app is a starter example, and can be run with `yarn install && yarn start`.

View File

@ -1,42 +0,0 @@
{
"env": {
"development": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": 2
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "inline"
}
},
"production": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": 2
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "none"
}
}
}
}

View File

@ -1,9 +0,0 @@
{
"extends": "eslint-config-airbnb",
"rules": {
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": [2, { "ignore": ["electron"] }],
"linebreak-style": 0
}
}

4
minimal/.gitignore vendored
View File

@ -1,4 +0,0 @@
node_modules/
Cargo.lock
target/
dist/

View File

@ -1,30 +0,0 @@
[package]
authors = ["Bradlee Speice"]
categories = ["wasm"]
description = "A no-framework WASM Electron app"
license = "Apache-2.0/MIT"
name = "rust_webpack"
readme = "./README.md"
repository = "https://github.com/rustwasm/rust-webpack-template"
version = "0.1.0"
[lib]
crate-type = ["cdylib"]
[dependencies]
cfg-if = "0.1.5"
wasm-bindgen = "0.2.19"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.5", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
wee_alloc = { version = "0.4.2", optional = true }
[features]
default-features = ["console_error_panic_hook", "wee_alloc"]

View File

@ -1,25 +0,0 @@
DIR="$(dirname $0)"
WASM_DIR="$DIR/target/wasm32-unknown-unknown"
WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
APP_DIR="$DIR/dist/"
if [ ! -d "$APP_DIR" ]; then
mkdir "$APP_DIR"
fi
cp "$DIR/static/"* "$APP_DIR"
if [ -z "$(which cargo)" ]; then
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
exit 1
fi
if [ -z "$(which wasm-bindgen)" ]; then
echo "Installing wasm-bindgen-cli"
cargo install wasm-bindgen-cli
fi
cargo +nightly build --target=wasm32-unknown-unknown && \
wasm-bindgen "$WASM_DIR/debug/$WASM_NAME.wasm" --out-dir "$APP_DIR" --no-typescript && \
# Have to use --mode=development so we can patch out the call to instantiateStreaming
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/app_loader.js" -o "$APP_DIR/bundle.js" && \
sed -i 's/.*instantiateStreaming.*//g' "$APP_DIR/bundle.js"

View File

@ -1,66 +0,0 @@
{
"name": "electron_percy_wasm",
"productName": "electron_percy_wasm",
"version": "1.0.0",
"description": "My Electron application description",
"main": "dist/index.js",
"scripts": {
"prestart": "./build.sh",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"lint": "eslint src"
},
"keywords": [],
"author": "bspeice",
"license": "MIT",
"config": {
"forge": {
"make_targets": {
"win32": [
"squirrel"
],
"darwin": [
"zip"
],
"linux": [
"deb",
"rpm"
]
},
"electronPackagerConfig": {
"packageManager": "yarn"
},
"electronWinstallerConfig": {
"name": "electron_percy_wasm"
},
"electronInstallerDebian": {},
"electronInstallerRedhat": {},
"github_repository": {
"owner": "",
"name": ""
},
"windowsStoreConfig": {
"packageName": "",
"name": "electron_percy_wasm"
}
}
},
"dependencies": {
"electron-compile": "^6.4.3",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
},
"devDependencies": {
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"electron-forge": "^5.2.2",
"electron-prebuilt-compile": "2.0.7",
"eslint": "^3",
"eslint-config-airbnb": "^15",
"eslint-plugin-import": "^2",
"eslint-plugin-jsx-a11y": "^5",
"eslint-plugin-react": "^7"
}
}

View File

@ -1,54 +0,0 @@
use wasm_bindgen::prelude::*;
cfg_if! {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function to get better error messages if we ever panic.
if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook;
use console_error_panic_hook::set_once as set_panic_hook;
}
}
cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
if #[cfg(feature = "wee_alloc")] {
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
}
}
// Definitions of the functionality available in JS, which wasm-bindgen will
// generate shims for today (and eventually these should be near-0 cost!)
//
// These definitions need to be hand-written today but the current vision is
// that we'll use WebIDL to generate this `extern` block into a crate which you
// can link and import. There's a tracking issue for this at
// https://github.com/rustwasm/wasm-bindgen/issues/42
//
// In the meantime these are written out by hand and correspond to the names and
// signatures documented on MDN, for example
#[wasm_bindgen]
extern "C" {
type HTMLDocument;
static document: HTMLDocument;
#[wasm_bindgen(method)]
fn createElement(this: &HTMLDocument, tagName: &str) -> Element;
#[wasm_bindgen(method, getter)]
fn body(this: &HTMLDocument) -> Element;
type Element;
#[wasm_bindgen(method, setter = innerHTML)]
fn set_inner_html(this: &Element, html: &str);
#[wasm_bindgen(method, js_name = appendChild)]
fn append_child(this: &Element, other: Element);
}
// Called by our JS entry point to run the example
#[wasm_bindgen]
pub fn run() {
let val = document.createElement("p");
val.set_inner_html("IT IS ALIVE");
document.body().append_child(val);
}

View File

@ -1,8 +0,0 @@
const app = import("./rust_webpack")
app.then(module => {
console.log("Finished resolving application bundle")
module.run()
}, (e) => {
console.log("Unable to resolve application bundle: ")
console.log(e)
})

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script src="./bundle.js"/>
</html>

View File

@ -1,52 +0,0 @@
import { app, BrowserWindow } from 'electron';
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/index.html`);
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
};
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
{
"env": {
"development": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": 2
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "inline"
}
},
"production": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": 2
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "none"
}
}
}
}

View File

@ -1,9 +0,0 @@
{
"extends": "eslint-config-airbnb",
"rules": {
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": [2, { "ignore": ["electron"] }],
"linebreak-style": 0
}
}

94
yew/.gitignore vendored
View File

@ -1,4 +1,94 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
.DS_Store
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/ node_modules/
Cargo.lock jspm_packages/
target/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Webpack
.webpack/
# Electron-Forge
out/
node_modules/
dist/ dist/
target/

568
yew/Cargo.lock generated Normal file
View File

@ -0,0 +1,568 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "anyhow"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
[[package]]
name = "anymap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "bincode"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
dependencies = [
"byteorder",
"serde",
]
[[package]]
name = "boolinator"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
[[package]]
name = "bumpalo"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "bytes"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-match"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8100e46ff92eb85bf6dc2930c73f2a4f7176393c84a9446b3d501e1b354e7b34"
[[package]]
name = "console_error_panic_hook"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "futures"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
[[package]]
name = "futures-executor"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
[[package]]
name = "futures-macro"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc"
[[package]]
name = "futures-task"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
dependencies = [
"once_cell",
]
[[package]]
name = "futures-util"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
"slab",
]
[[package]]
name = "gloo"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ce6f2dfa9f57f15b848efa2aade5e1850dc72986b87a2b0752d44ca08f4967"
dependencies = [
"gloo-console-timer",
"gloo-events",
"gloo-file",
"gloo-timers",
]
[[package]]
name = "gloo-console-timer"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b48675544b29ac03402c6dffc31a912f716e38d19f7e74b78b7e900ec3c941ea"
dependencies = [
"web-sys",
]
[[package]]
name = "gloo-events"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "088514ec8ef284891c762c88a66b639b3a730134714692ee31829765c5bc814f"
dependencies = [
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-file"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9fecfe46b5dc3cc46f58e98ba580cc714f2c93860796d002eb3527a465ef49"
dependencies = [
"gloo-events",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-timers"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f"
dependencies = [
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "hashbrown"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb"
dependencies = [
"autocfg",
]
[[package]]
name = "http"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]]
name = "indexmap"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "once_cell"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]]
name = "pin-project"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro-hack"
version = "0.5.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
[[package]]
name = "proc-macro-nested"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
[[package]]
name = "proc-macro2"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "syn"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "thiserror"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasm-bindgen"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ad6e4e8b2b7f8c90b6e09a9b590ea15cb0d1dbe28502b5a405cd95d1981671"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
[[package]]
name = "web-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "yew"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d82d3fb2ab53913967b0a50a5a693ab75e1465cb091a24519a9441246c2627"
dependencies = [
"anyhow",
"anymap",
"bincode",
"cfg-if",
"cfg-match",
"console_error_panic_hook",
"futures",
"gloo",
"http",
"indexmap",
"js-sys",
"log",
"proc-macro-hack",
"proc-macro-nested",
"ryu",
"serde",
"serde_json",
"slab",
"thiserror",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"yew-macro",
]
[[package]]
name = "yew-macro"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a9a452e63b6222b28b426dafbc6b207192e0127cdb93324cc7407b8c7e1768"
dependencies = [
"boolinator",
"lazy_static",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "yew_electron"
version = "0.1.0"
dependencies = [
"js-sys",
"wasm-bindgen",
"yew",
]

View File

@ -1,12 +1,13 @@
[package] [package]
name = "electron_yew_wasm" name = "yew_electron"
version = "0.1.0" version = "0.1.0"
authors = ["Bradlee Speice <bradlee@speice.io>"] authors = ["Bradlee Speice <bradlee@speice.io>"]
edition = "2018"
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
stdweb = "0.4" js-sys = "0.3"
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
yew = { git = "https://github.com/DenisKolodin/yew" } yew = "0.17"

View File

@ -1,25 +1,18 @@
DIR="$(dirname $0)" DIR="$(dirname $0)"
WASM_DIR="$DIR/target/wasm32-unknown-unknown" WASM_DIR="$DIR/target/wasm32-unknown-unknown"
WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')" NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
APP_DIR="$DIR/dist/" APP_DIR="$DIR/dist"
if [ ! -d "$APP_DIR" ]; then if [ ! -d "$APP_DIR" ]; then
mkdir "$APP_DIR" mkdir "$APP_DIR"
fi fi
cp "$DIR/static/"* "$APP_DIR" cp "$DIR/static/"* "$APP_DIR"
if [ -z "$(which cargo)" ]; then # Note: We'd normally prefer to use something like `wasm-pack` as a "production-ready" packager.
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.' # However, when `wasm-pack` runs, it uses `wasm-bindgen` (which ultimately uses webpack 4.X) to
exit 1 # build the Javascript bindings and thus still suffers from webpack/webpack#7918. Because we use
fi # the webpack CLI directly here, we benefit from changes in 5.X (specifically,
# the `asyncWebAssembly` experiment).
if [ -z "$(which wasm-bindgen)" ]; then cargo build --target=wasm32-unknown-unknown && \
echo "Installing wasm-bindgen-cli" wasm-bindgen "$WASM_DIR/debug/$NAME.wasm" --out-dir "$APP_DIR" && \
cargo install wasm-bindgen-cli "$DIR/node_modules/webpack-cli/bin/cli.js" "$APP_DIR/$NAME.js" -o "$APP_DIR/bundle.js"
fi
cargo +nightly build --target=wasm32-unknown-unknown && \
wasm-bindgen "$WASM_DIR/debug/$WASM_NAME.wasm" --out-dir "$APP_DIR" --no-typescript && \
# Have to use --mode=development so we can patch out the call to instantiateStreaming
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/app_loader.js" -o "$APP_DIR/bundle.js" && \
sed -i 's/.*instantiateStreaming.*//g' "$APP_DIR/bundle.js"

View File

@ -1,66 +1,61 @@
{ {
"name": "electron_percy_wasm", "name": "seed",
"productName": "electron_percy_wasm", "productName": "seed",
"version": "1.0.0", "version": "1.0.0",
"description": "My Electron application description", "description": "My Electron application description",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"prestart": "./build.sh", "prestart": "./build.sh",
"start": "electron-forge start", "start": "electron-forge start",
"package": "electron-forge package", "package": "electron-forge package",
"make": "electron-forge make", "make": "electron-forge make",
"lint": "eslint src" "publish": "electron-forge publish",
}, "lint": "echo \"No linting configured\""
"keywords": [], },
"author": "bspeice", "keywords": [],
"license": "MIT", "author": {
"config": { "name": "Bradlee Speice",
"forge": { "email": "bradlee@speice.io"
"make_targets": { },
"win32": [ "license": "MIT",
"squirrel" "config": {
], "forge": {
"darwin": [ "packagerConfig": {},
"zip" "makers": [
], {
"linux": [ "name": "@electron-forge/maker-squirrel",
"deb", "config": {
"rpm" "name": "seed"
] }
}, },
"electronPackagerConfig": { {
"packageManager": "yarn" "name": "@electron-forge/maker-zip",
}, "platforms": [
"electronWinstallerConfig": { "darwin"
"name": "electron_percy_wasm" ]
}, },
"electronInstallerDebian": {}, {
"electronInstallerRedhat": {}, "name": "@electron-forge/maker-deb",
"github_repository": { "config": {}
"owner": "", },
"name": "" {
}, "name": "@electron-forge/maker-rpm",
"windowsStoreConfig": { "config": {}
"packageName": "",
"name": "electron_percy_wasm"
}
} }
}, ]
"dependencies": {
"electron-compile": "^6.4.3",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
},
"devDependencies": {
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"electron-forge": "^5.2.2",
"electron-prebuilt-compile": "2.0.7",
"eslint": "^3",
"eslint-config-airbnb": "^15",
"eslint-plugin-import": "^2",
"eslint-plugin-jsx-a11y": "^5",
"eslint-plugin-react": "^7"
} }
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"webpack": "^5.0.0-beta.22",
"webpack-cli": "^3.3.12"
},
"devDependencies": {
"@electron-forge/cli": "6.0.0-beta.52",
"@electron-forge/maker-deb": "6.0.0-beta.52",
"@electron-forge/maker-rpm": "6.0.0-beta.52",
"@electron-forge/maker-squirrel": "6.0.0-beta.52",
"@electron-forge/maker-zip": "6.0.0-beta.52",
"electron": "9.1.1"
}
} }

View File

@ -1,40 +1,68 @@
extern crate wasm_bindgen; #![recursion_limit = "256"]
#[macro_use]
extern crate yew;
use js_sys::Date;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use yew::prelude::*; use yew::services::ConsoleService;
use yew::{html, Component, ComponentLink, Html, ShouldRender};
struct Model {} pub struct Model {
enum Msg { link: ComponentLink<Self>,
value: i64,
}
pub enum Msg {
Increment,
Decrement,
} }
impl Component for Model { impl Component for Model {
type Message = Msg; type Message = Msg;
type Properties = (); type Properties = ();
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
Model {} Model { link, value: 0 }
} }
fn update(&mut self, _msg: Self::Message) -> ShouldRender { fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::Increment => {
self.value += 1;
ConsoleService::log("plus one");
}
Msg::Decrement => {
self.value -= 1;
ConsoleService::log("minus one");
}
}
true
}
fn change(&mut self, _: Self::Properties) -> ShouldRender {
false false
} }
}
impl Renderable<Model> for Model { fn view(&self) -> Html {
fn view(&self) -> Html<Self> {
html! { html! {
<p>{ "IT'S ALIVE" }</p> <div>
<nav class="menu">
<button onclick=self.link.callback(|_| Msg::Increment)>
{ "Increment" }
</button>
<button onclick=self.link.callback(|_| Msg::Decrement)>
{ "Decrement" }
</button>
<button onclick=self.link.batch_callback(|_| vec![Msg::Increment, Msg::Increment])>
{ "Increment Twice" }
</button>
</nav>
<p>{ self.value }</p>
<p>{ Date::new_0().to_string().as_string().unwrap() }</p>
</div>
} }
} }
} }
#[wasm_bindgen] #[wasm_bindgen(start)]
pub fn main() { pub fn main() {
yew::initialize(); yew::start_app::<Model>();
let app: App<Model> = App::new();
app.mount_to_body();
yew::run_loop();
} }

View File

@ -1,3 +0,0 @@
import { main } from "./electron_yew_wasm"
main()

View File

@ -1,8 +0,0 @@
// We have to have a two-stage loader because WebPack says we do
const app = import("./app")
app.then(() => {
console.log("Finished resolving application bundle")
}, (e) => {
console.log("Unable to resolve application bundle: ")
console.log(e)
})

6
yew/static/index.css Normal file
View File

@ -0,0 +1,6 @@
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: auto;
max-width: 38rem;
padding: 2rem;
}

View File

@ -1,11 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="UTF-8" />
<title></title> <title>Hello World!</title>
<link rel="stylesheet" href="index.css" />
</head> </head>
<body> <body></body>
<div id="root">Loading...</div>
</body> <script src="./bundle.js"></script>
<script src="./bundle.js"/>
</html> </html>

View File

@ -1,29 +1,23 @@
import { app, BrowserWindow } from 'electron'; const { app, BrowserWindow } = require('electron');
const path = require('path');
// Keep a global reference of the window object, if you don't, the window will // Handle creating/removing shortcuts on Windows when installing/uninstalling.
// be closed automatically when the JavaScript object is garbage collected. if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
let mainWindow; app.quit();
}
const createWindow = () => { const createWindow = () => {
// Create the browser window. // Create the browser window.
mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
}); });
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/index.html`); mainWindow.loadFile(path.join(__dirname, 'index.html'));
// Open the DevTools. // Open the DevTools.
mainWindow.webContents.openDevTools(); mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}; };
// This method will be called when Electron has finished // This method will be called when Electron has finished
@ -31,10 +25,10 @@ const createWindow = () => {
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', createWindow); app.on('ready', createWindow);
// Quit when all windows are closed. // Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit(); app.quit();
} }
@ -43,7 +37,7 @@ app.on('window-all-closed', () => {
app.on('activate', () => { app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the // On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (mainWindow === null) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow(); createWindow();
} }
}); });

6
yew/webpack.config.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
experiments: {
asyncWebAssembly: true,
importAsync: true,
}
}

File diff suppressed because it is too large Load Diff