You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(examples): update example crates and core logic
- Updated example crates (hello_svelte, reposition, styled, toggle) for improved state management and reset logic.
- Modified `src/pane.rs` and example source files for better robustness and compatibility.
- Updated Webpack and package configuration in `examples/www` for build improvements.
- Improved documentation in `README.md`.
Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,11 @@ The features can be summarized as:
25
25
26
26
The examples in this crate are hosted online: [div-rs Examples](https://div.paddlers.ch/)
27
27
28
-
Have a look at the code in example directory. The best way is to clone the repository and run it locally, so you can play around with the code.
28
+
Below is an example of the output you can generate with the built-in GIF capture tool:
29
+
30
+

31
+
32
+
Have a look at the code in the example directory. The best way is to clone the repository and run it locally, so you can play around with the code and generate your own GIFs.
Copy file name to clipboardExpand all lines: examples/hello_svelte/src/lib.rs
+16-7Lines changed: 16 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,24 @@
1
1
use wasm_bindgen::prelude::*;
2
2
3
-
#[wasm_bindgen(start)]
3
+
#[wasm_bindgen]
4
4
pubfnmain(){
5
-
div::init_to("div-root").unwrap();
6
5
set_panic_hook();
7
6
8
-
// Create a new pane at offset (100,100) from body
9
-
// with size 500px/500px and then create a single
10
-
// text node inside it with an external class stored in TODO
7
+
// Defensive: check for double initialization
8
+
match div::init_to("div-root"){
9
+
Ok(_) => {},
10
+
Err(e) => {
11
+
panic!("[hello_svelte] div::init_to('div-root') failed: {e:?}.\nThis usually means main() was called without a prior reset, or reset did not complete before main().");
12
+
}
13
+
}
14
+
11
15
constX:u32 = 0;
12
16
constY:u32 = 0;
13
17
constW:u32 = 500;
14
18
constH:u32 = 500;
15
19
let class = div::JsClass::preregistered("MyComponent")
16
-
.expect("JS class Test has not been registered properly");
.unwrap_or_else(|| panic!("[hello_svelte] Svelte component 'MyComponent' is not registered.\n\nMake sure register_svelte_component('MyComponent', ...) is called in JS before calling main()."));
0 commit comments