script_bridge.rs, index.js
This commit is contained in:
parent
a58ea4fba5
commit
a299ae1082
|
@ -1,7 +1,9 @@
|
||||||
port = 8080
|
port = 8080
|
||||||
# port = 8443
|
# port = 8443
|
||||||
https = false
|
https = false
|
||||||
cache_busting = true
|
# @TODO how to import `pkg/frontend.js` with enabled cache busting?
|
||||||
|
# @TODO add a switch to enable Typescript generator in mzoon?
|
||||||
|
cache_busting = false
|
||||||
backend_log_level = "warn" # "error" / "warn" / "info" / "debug" / "trace"
|
backend_log_level = "warn" # "error" / "warn" / "info" / "debug" / "trace"
|
||||||
|
|
||||||
[redirect]
|
[redirect]
|
||||||
|
@ -23,4 +25,6 @@ frontend = [
|
||||||
backend = [
|
backend = [
|
||||||
"backend/Cargo.toml",
|
"backend/Cargo.toml",
|
||||||
"backend/src",
|
"backend/src",
|
||||||
|
"backend/index.js",
|
||||||
|
"backend/style.css",
|
||||||
]
|
]
|
||||||
|
|
2
backend/index.js
Normal file
2
backend/index.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import { FW } from '/_api/pkg/frontend.js';
|
||||||
|
window.FW = FW;
|
|
@ -5,6 +5,10 @@ async fn frontend() -> Frontend {
|
||||||
"<style>",
|
"<style>",
|
||||||
include_str!("../style.css"),
|
include_str!("../style.css"),
|
||||||
"</style>"
|
"</style>"
|
||||||
|
)).append_to_head(concat!(
|
||||||
|
"<script type=\"module\">",
|
||||||
|
include_str!("../index.js"),
|
||||||
|
"</script>"
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::rc::Rc;
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
mod platform;
|
mod platform;
|
||||||
|
mod script_bridge;
|
||||||
|
|
||||||
mod controls_panel;
|
mod controls_panel;
|
||||||
use controls_panel::ControlsPanel;
|
use controls_panel::ControlsPanel;
|
||||||
|
|
21
frontend/src/script_bridge.rs
Normal file
21
frontend/src/script_bridge.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use zoon::{*, println};
|
||||||
|
|
||||||
|
#[wasm_bindgen(inline_js = r#"export function strict_eval(code) { return eval?.(`"use strict"; ${code};`) }"#)]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(catch)]
|
||||||
|
pub fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct FW;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl FW {
|
||||||
|
pub fn do_something() {
|
||||||
|
println!("Command result: {:#?}", strict_eval("FW.do_something_else();"));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn do_something_else() {
|
||||||
|
println!("ELSE!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue