Skip to content

Commit

Permalink
Re-export wasm-bindgen, js-sys, and event types from web-sys (#642
Browse files Browse the repository at this point in the history
)

* re-export web_sys for user convenience

* also re-exporting js_sys

* also adding wasm_bindgen because of JsValue

* Only re-export HTML events instead of web-sys

web-sys relies very haevily of feature flags to determine which parts of the API is compiled. Sycamore itself enables a subset of these flags but in many cases, the downstream user will need to add web-sys anyways should they wish to use an API not enabled by Sycamore.

* Remove wasm-bindgen from examples

---------

Co-authored-by: Blaine Hansen <faichenshing@gmail.com>
  • Loading branch information
lukechu10 and blainehansen authored Oct 20, 2023
1 parent bc25aae commit e49c74c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion examples/js-framework-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ console_error_panic_hook = "0.1.7"
getrandom = { version = "0.2.8", features = ["js"] }
rand = "0.8.5"
sycamore = { path = "../../packages/sycamore" }
wasm-bindgen = "0.2.83"
web-sys = "0.3.60"
3 changes: 1 addition & 2 deletions examples/todomvc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.89"
sycamore = { path = "../../packages/sycamore", features = ["serde"] }
uuid = { version = "1.2.2", features = ["serde", "v4", "js"] }
wasm-bindgen = "0.2.83"

[dependencies.web-sys]
features = ["InputEvent", "KeyboardEvent", "Location", "Storage"]
features = ["Location", "Storage"]
version = "0.3.60"
14 changes: 14 additions & 0 deletions packages/sycamore-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ pub use ssr_node::*;
use sycamore_core::generic_node::{GenericNode, GenericNodeElements};
use sycamore_reactive::*;
use wasm_bindgen::prelude::*;
/// Re-export of `js-sys` and `wasm-bindgen` for convenience.
#[doc(no_inline)]
pub use {js_sys, wasm_bindgen};

/// Re-export of HTML event types from `web-sys` for convenience.
pub mod events {
pub use web_sys::{
AnimationEvent, BeforeUnloadEvent, CompositionEvent, DeviceMotionEvent,
DeviceOrientationEvent, DragEvent, ErrorEvent, Event, FocusEvent, GamepadEvent,
HashChangeEvent, KeyboardEvent, MessageEvent, MouseEvent, PageTransitionEvent,
PointerEvent, PopStateEvent, ProgressEvent, StorageEvent, TouchEvent, TransitionEvent,
UiEvent, WheelEvent,
};
}

/// Trait that is implemented by all [`GenericNode`] backends that render to HTML.
pub trait Html:
Expand Down

0 comments on commit e49c74c

Please sign in to comment.