Implement event/response roundtrip (#49)

This commit is contained in:
TrueDoctor
2021-03-28 00:23:41 +01:00
committed by GitHub
parent 04dc05e575
commit 0e553adb32
9 changed files with 112 additions and 26 deletions
+11 -7
View File
@@ -4,23 +4,27 @@ pub mod viewport;
pub mod window;
pub mod wrappers;
use graphite_editor_core::Editor;
use graphite_editor_core::{events::Response, Callback, Editor};
use std::cell::RefCell;
use wasm_bindgen::prelude::*;
// the thread_local macro provides a way to initialize static variables with non-constant functions
thread_local! {pub static EDITOR_STATE: RefCell<Editor> = RefCell::new(Editor::new())}
thread_local! {pub static EDITOR_STATE: RefCell<Editor> = RefCell::new(Editor::new(Box::new(handle_response)))}
#[wasm_bindgen(start)]
pub fn init() {
utils::set_panic_hook();
}
/// Send events
#[wasm_bindgen]
pub fn handle_event(event_name: String) {
// TODO: add payload
todo!()
fn handle_response(response: Response) {
match response {
Response::UpdateCanvas => update_canvas(),
}
}
#[wasm_bindgen(module = "/../src/wasm-callback-processor.js")]
extern "C" {
fn update_canvas();
}
#[wasm_bindgen]