mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 09:08:13 +08:00
Implement event/response roundtrip (#49)
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user