diff --git a/CHANGELOG.md b/CHANGELOG.md index 819c2b6..28fa3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] - +## [0.7.0] - 2023-09-30 ### New Functions 🚀 @@ -29,12 +29,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 a `web_sys::MutationObserverInit`. - `use_websocket`: - takes now a `&str` instead of a `String` as its `url` parameter. + - same for the returned `send` method. - The `ready_state` return type is now renamed to `ConnectionReadyState` instead of `UseWebSocketReadyState`. - The returned signals `ready_state`, `message`, `message_bytes` have now the type `Signal<...>` instead of `ReadSignal<...>` to make them more consistent with other functions. - The options `reconnect_limit` and `reconnect_interval` now take a `u64` instead of `Option` to improve DX. - The option `manual` has been renamed to `immediate` to make it more consistent with other functions. To port please note that `immediate` is the inverse of `manual` (`immediate` = `!manual`). + - Added documentation how pass it ergonomically as context. - `use_color_mode`: - The optional `on_changed` handler parameters have changed slightly. Please refer to the docs for more details. - Throttled or debounced functions cannot be `FnOnce` anymore. @@ -45,8 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `use_websocket` can use relative urls now - Callbacks in options don't require to be cloneable anymore - Callback in `use_raf_fn` doesn't require to be cloneable anymore -- All (!) functions can now be safely called on the server. Specifically this includes the following that -- panicked on the server: +- All (!) functions can now be safely called on the server. Specifically this includes the following that before + panicked on the server: - `use_scroll` - `use_event_listener` - `use_element_hover` diff --git a/Cargo.toml b/Cargo.toml index 2b5b433..444bf29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-use" -version = "0.7.0-rc" +version = "0.7.0" edition = "2021" authors = ["Marc-Stefan Cassola"] categories = ["gui", "web-programming"] @@ -13,7 +13,7 @@ repository = "https://github.com/Synphonyte/leptos-use" homepage = "https://leptos-use.rs" [dependencies] -leptos = "0.5.0-rc2" +leptos = "0.5" wasm-bindgen = "0.2" js-sys = "0.3" default-struct-builder = "0.5" diff --git a/README.md b/README.md index 16b0401..bbfed70 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Crates.io SSR Docs & Demos - 51 Functions + 58 Functions


@@ -82,7 +82,8 @@ python3 post_build.py use_storage ### New Function Template -To scaffold a new function quickly you can run `template/createfn.sh`. It requires that [`ffizer`](https://ffizer.github.io/) is installed. +To scaffold a new function quickly you can run `template/createfn.sh`. It requires that [`ffizer`](https://ffizer.github.io/) and Python 3 is installed. +This will create the function file in the src directory, scaffold an example directory and an entry in the book. ## Leptos compatibility @@ -90,4 +91,4 @@ To scaffold a new function quickly you can run `template/createfn.sh`. It requir |---------------|---------------------------| | <= 0.3 | 0.3 | | 0.4, 0.5, 0.6 | 0.4 | -| main | 0.5.0-alpha/beta/rc | +| 0.7 | 0.5 | diff --git a/docs/add_version_to_docs.py b/docs/add_version_to_docs.py index 60f5b0d..68a28da 100644 --- a/docs/add_version_to_docs.py +++ b/docs/add_version_to_docs.py @@ -64,7 +64,7 @@ def add_to_compat_table(leptos_version: str, crate_version: str, original_text: if table_row is None: lines.append(f"| {crate_version} | {leptos_version} |") - elif re.search(rf"^\| .*? {crate_version}\s*\| {leptos_version}", table_row) is not None: + elif re.search(rf"^\| (.* )?{crate_version}\s*\| {leptos_version}", table_row) is not None: return original_text else: index = table_row.index("|", 1) diff --git a/docs/book/src/introduction.md b/docs/book/src/introduction.md index 2f0b81e..5824f3a 100644 --- a/docs/book/src/introduction.md +++ b/docs/book/src/introduction.md @@ -12,6 +12,6 @@ Crates.io SSR Docs & Demos - 51 Functions + 58 Functions

\ No newline at end of file diff --git a/examples/on_click_outside/Cargo.toml b/examples/on_click_outside/Cargo.toml index 7aa80ab..76f570c 100644 --- a/examples/on_click_outside/Cargo.toml +++ b/examples/on_click_outside/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/signal_debounced/Cargo.toml b/examples/signal_debounced/Cargo.toml index e55d823..a14e69e 100644 --- a/examples/signal_debounced/Cargo.toml +++ b/examples/signal_debounced/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/signal_throttled/Cargo.toml b/examples/signal_throttled/Cargo.toml index 0cf5bae..78525ed 100644 --- a/examples/signal_throttled/Cargo.toml +++ b/examples/signal_throttled/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml index 5dc2404..7b30d87 100644 --- a/examples/ssr/Cargo.toml +++ b/examples/ssr/Cargo.toml @@ -11,10 +11,10 @@ axum = { version = "0.6.4", optional = true } console_error_panic_hook = "0.1" console_log = "1" cfg-if = "1" -leptos = { version = "0.5.0-rc2", features = ["nightly"] } -leptos_axum = { version = "0.5.0-rc2", optional = true } -leptos_meta = { version = "0.5.0-rc2", features = ["nightly"] } -leptos_router = { version = "0.5.0-rc2", features = ["nightly"] } +leptos = { version = "0.5", features = ["nightly"] } +leptos_axum = { version = "0.5", optional = true } +leptos_meta = { version = "0.5", features = ["nightly"] } +leptos_router = { version = "0.5", features = ["nightly"] } leptos-use = { path = "../..", features = ["storage"] } log = "0.4" simple_logger = "4" diff --git a/examples/ssr/src/app.rs b/examples/ssr/src/app.rs index 29e62fc..91e95b8 100644 --- a/examples/ssr/src/app.rs +++ b/examples/ssr/src/app.rs @@ -64,10 +64,24 @@ fn HomePage() -> impl IntoView { debounced_fn(); view! { -

Leptos-Use SSR Example

- -

Locale zh-Hans-CN-u-nu-hanidec: {zh_count}

-

Press any key: {key}

-

Debounced called: {debounce_value}

+

+ Leptos-Use SSR Example +

+ +

+ Locale zh-Hans-CN-u-nu-hanidec: + {zh_count} +

+

+ Press any key: + {key} +

+

+ Debounced called: + {debounce_value} +

} } diff --git a/examples/ssr/src/error_template.rs b/examples/ssr/src/error_template.rs index 25179a3..83cbbe3 100644 --- a/examples/ssr/src/error_template.rs +++ b/examples/ssr/src/error_template.rs @@ -61,7 +61,7 @@ pub fn ErrorTemplate( // a unique key for each item as a reference key=|(index, _error)| *index // renders each item to a view - view=move |error| { + children=move |error| { let error_string = error.1.to_string(); let error_code = error.1.status_code(); view! { diff --git a/examples/use_abs/Cargo.toml b/examples/use_abs/Cargo.toml index ca9275d..69755fa 100644 --- a/examples/use_abs/Cargo.toml +++ b/examples/use_abs/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_active_element/Cargo.toml b/examples/use_active_element/Cargo.toml index 09fa7ba..291f327 100644 --- a/examples/use_active_element/Cargo.toml +++ b/examples/use_active_element/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_active_element/src/main.rs b/examples/use_active_element/src/main.rs index 6c84ab2..e18fe28 100644 --- a/examples/use_active_element/src/main.rs +++ b/examples/use_active_element/src/main.rs @@ -22,10 +22,10 @@ fn Demo() -> impl IntoView { } - } - /> + let:i + > + + diff --git a/examples/use_breakpoints/Cargo.toml b/examples/use_breakpoints/Cargo.toml index ff943e3..99c6719 100644 --- a/examples/use_breakpoints/Cargo.toml +++ b/examples/use_breakpoints/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_ceil/Cargo.toml b/examples/use_ceil/Cargo.toml index c425802..059b96b 100644 --- a/examples/use_ceil/Cargo.toml +++ b/examples/use_ceil/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_color_mode/Cargo.toml b/examples/use_color_mode/Cargo.toml index 2ca3ec2..308c9c2 100644 --- a/examples/use_color_mode/Cargo.toml +++ b/examples/use_color_mode/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_css_var/Cargo.toml b/examples/use_css_var/Cargo.toml index 6b3b809..36dccaf 100644 --- a/examples/use_css_var/Cargo.toml +++ b/examples/use_css_var/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_cycle_list/Cargo.toml b/examples/use_cycle_list/Cargo.toml index a6d6fe8..2c954a7 100644 --- a/examples/use_cycle_list/Cargo.toml +++ b/examples/use_cycle_list/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_debounce_fn/Cargo.toml b/examples/use_debounce_fn/Cargo.toml index 450093a..8fd9049 100644 --- a/examples/use_debounce_fn/Cargo.toml +++ b/examples/use_debounce_fn/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_document_visibility/Cargo.toml b/examples/use_document_visibility/Cargo.toml index c8c2d63..61607d2 100644 --- a/examples/use_document_visibility/Cargo.toml +++ b/examples/use_document_visibility/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_draggable/Cargo.toml b/examples/use_draggable/Cargo.toml index 561c57e..c56104c 100644 --- a/examples/use_draggable/Cargo.toml +++ b/examples/use_draggable/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_drop_zone/Cargo.toml b/examples/use_drop_zone/Cargo.toml index 7d1e12b..461f924 100644 --- a/examples/use_drop_zone/Cargo.toml +++ b/examples/use_drop_zone/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_drop_zone/src/main.rs b/examples/use_drop_zone/src/main.rs index 67b8588..d70c460 100644 --- a/examples/use_drop_zone/src/main.rs +++ b/examples/use_drop_zone/src/main.rs @@ -42,29 +42,27 @@ fn Demo() -> impl IntoView { -

- Name: - {file.name()} -

-

- Size: - {file.size()} -

-

- Type: - {file.type_()} -

-

- Last modified: - {file.last_modified()} -

- - } - } - /> + let:file + > +
+

+ Name: + {file.name()} +

+

+ Size: + {file.size()} +

+

+ Type: + {file.type_()} +

+

+ Last modified: + {file.last_modified()} +

+
+
diff --git a/examples/use_element_hover/Cargo.toml b/examples/use_element_hover/Cargo.toml index 03a7888..8f11c26 100644 --- a/examples/use_element_hover/Cargo.toml +++ b/examples/use_element_hover/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_element_size/Cargo.toml b/examples/use_element_size/Cargo.toml index 9597609..3e070b8 100644 --- a/examples/use_element_size/Cargo.toml +++ b/examples/use_element_size/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_element_visibility/Cargo.toml b/examples/use_element_visibility/Cargo.toml index 193f95a..7c6bf4c 100644 --- a/examples/use_element_visibility/Cargo.toml +++ b/examples/use_element_visibility/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_event_listener/Cargo.toml b/examples/use_event_listener/Cargo.toml index f608898..3b07dcd 100644 --- a/examples/use_event_listener/Cargo.toml +++ b/examples/use_event_listener/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_favicon/Cargo.toml b/examples/use_favicon/Cargo.toml index 342291d..3d9be8b 100644 --- a/examples/use_favicon/Cargo.toml +++ b/examples/use_favicon/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_favicon/src/main.rs b/examples/use_favicon/src/main.rs index 6e9775c..a021e80 100644 --- a/examples/use_favicon/src/main.rs +++ b/examples/use_favicon/src/main.rs @@ -21,6 +21,7 @@ fn Demo() -> impl IntoView { set_icon.set(Some("favicon-leptos.ico".into())); } > + impl IntoView { set_icon.set(Some("favicon-red.svg".into())); } > + impl IntoView { set_icon.set(Some("favicon-green.svg".into())); } > + impl IntoView { set_icon.set(Some("favicon-blue.svg".into())); } > + impl IntoView { set_icon.set(Some("favicon-orange.svg".into())); } > + impl IntoView { view! {
-    coords: {move || if let Some(coords) = coords() {
-                        format!(r#"{{
+            coords:
+            {move || {
+                if let Some(coords) = coords() {
+                    format!(
+                        r#"{{
         accuracy: {},
         latitude: {},
         longitude: {},
@@ -23,18 +26,25 @@ fn Demo() -> impl IntoView {
         altitude_accuracy: {:?},
         heading: {:?},
         speed: {:?},
-    }}"#, coords.accuracy(), coords.latitude(), coords.longitude(), coords.altitude(), coords.altitude_accuracy(), coords.heading(), coords.speed())
-                    } else {
-                        "None".to_string()
-                    }},
-    located_at: {located_at},
-    error: {move || if let Some(error) = error() {
-        error.message()
-    } else {"None".to_string()}},
-                
- - - } + }}"#, + coords.accuracy(), coords.latitude(), coords.longitude(), coords.altitude(), + coords.altitude_accuracy(), coords.heading(), coords.speed() + ) + } else { + "None".to_string() + } + }} + , + located_at: + {located_at} + , + error: + {move || if let Some(error) = error() { error.message() } else { "None".to_string() }} + , + + + + } } fn main() { diff --git a/examples/use_idle/Cargo.toml b/examples/use_idle/Cargo.toml index a58f3bc..8fbe4fc 100644 --- a/examples/use_idle/Cargo.toml +++ b/examples/use_idle/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_idle/src/main.rs b/examples/use_idle/src/main.rs index bd56b53..3ad03cb 100644 --- a/examples/use_idle/src/main.rs +++ b/examples/use_idle/src/main.rs @@ -14,13 +14,19 @@ fn Demo() -> impl IntoView { view! { - For demonstration purpose, the idle timeout is set to 5s in this demo (default 1min). + For demonstration purpose, the idle timeout is set to + + 5s + + in this demo (default 1min).
- Idle: + Idle: +
- Inactive: {idled_for}s + Inactive: + {idled_for} s
} } diff --git a/examples/use_intersection_observer/Cargo.toml b/examples/use_intersection_observer/Cargo.toml index aeee851..0ab8584 100644 --- a/examples/use_intersection_observer/Cargo.toml +++ b/examples/use_intersection_observer/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_interval/Cargo.toml b/examples/use_interval/Cargo.toml index 8155141..1955d1a 100644 --- a/examples/use_interval/Cargo.toml +++ b/examples/use_interval/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_interval_fn/Cargo.toml b/examples/use_interval_fn/Cargo.toml index 83f24a1..942ab19 100644 --- a/examples/use_interval_fn/Cargo.toml +++ b/examples/use_interval_fn/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_intl_number_format/Cargo.toml b/examples/use_intl_number_format/Cargo.toml index 4f8d229..dfafe71 100644 --- a/examples/use_intl_number_format/Cargo.toml +++ b/examples/use_intl_number_format/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_media_query/Cargo.toml b/examples/use_media_query/Cargo.toml index a773ef8..4b47f0b 100644 --- a/examples/use_media_query/Cargo.toml +++ b/examples/use_media_query/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_mouse/Cargo.toml b/examples/use_mouse/Cargo.toml index 6f836f1..7882fe0 100644 --- a/examples/use_mouse/Cargo.toml +++ b/examples/use_mouse/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_mouse/src/main.rs b/examples/use_mouse/src/main.rs index cb469f8..e96ac32 100644 --- a/examples/use_mouse/src/main.rs +++ b/examples/use_mouse/src/main.rs @@ -46,6 +46,7 @@ fn Demo() -> impl IntoView { mouse_default.y.get(), mouse_default.source_type.get() ) }} +

"Extractor Usage"

"Only works when the mouse is over the demo element" @@ -59,6 +60,7 @@ fn Demo() -> impl IntoView { .get(), mouse_with_extractor.y.get(), mouse_with_extractor.source_type.get() ) }} + } diff --git a/examples/use_mutation_observer/Cargo.toml b/examples/use_mutation_observer/Cargo.toml index dd12cd5..2f3dbe1 100644 --- a/examples/use_mutation_observer/Cargo.toml +++ b/examples/use_mutation_observer/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_mutation_observer/src/main.rs b/examples/use_mutation_observer/src/main.rs index db7cba4..d4ca625 100644 --- a/examples/use_mutation_observer/src/main.rs +++ b/examples/use_mutation_observer/src/main.rs @@ -46,8 +46,10 @@ fn Demo() -> impl IntoView { each=move || enum_msgs.get() // list only grows so this is fine here key=|message| message.0 - view=|message| view! {
"Mutation Attribute: " {message.1}
} - /> + let:message + > +
"Mutation Attribute: " {message.1}
+ } } diff --git a/examples/use_raf_fn/Cargo.toml b/examples/use_raf_fn/Cargo.toml index 1e486a4..305b65e 100644 --- a/examples/use_raf_fn/Cargo.toml +++ b/examples/use_raf_fn/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_resize_observer/Cargo.toml b/examples/use_resize_observer/Cargo.toml index 9d8d5d3..dc8b881 100644 --- a/examples/use_resize_observer/Cargo.toml +++ b/examples/use_resize_observer/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_round/Cargo.toml b/examples/use_round/Cargo.toml index 7574b9f..3956d90 100644 --- a/examples/use_round/Cargo.toml +++ b/examples/use_round/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_scroll/Cargo.toml b/examples/use_scroll/Cargo.toml index 5f40795..1e73a51 100644 --- a/examples/use_scroll/Cargo.toml +++ b/examples/use_scroll/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_storage/Cargo.toml b/examples/use_storage/Cargo.toml index c186182..09446d5 100644 --- a/examples/use_storage/Cargo.toml +++ b/examples/use_storage/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_storage/src/main.rs b/examples/use_storage/src/main.rs index f95165f..7f5442f 100644 --- a/examples/use_storage/src/main.rs +++ b/examples/use_storage/src/main.rs @@ -51,6 +51,7 @@ fn Demo() -> impl IntoView { set_state .update(|s| s.count = event_target_value(&e).parse::().unwrap() as u32) } + type="number" min="0" step="1" diff --git a/examples/use_throttle_fn/Cargo.toml b/examples/use_throttle_fn/Cargo.toml index fd2cb2a..d6e01f9 100644 --- a/examples/use_throttle_fn/Cargo.toml +++ b/examples/use_throttle_fn/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_timestamp/Cargo.toml b/examples/use_timestamp/Cargo.toml index f061227..76d8d40 100644 --- a/examples/use_timestamp/Cargo.toml +++ b/examples/use_timestamp/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_timestamp/src/main.rs b/examples/use_timestamp/src/main.rs index 093ffe3..b1e79ad 100644 --- a/examples/use_timestamp/src/main.rs +++ b/examples/use_timestamp/src/main.rs @@ -7,7 +7,10 @@ fn Demo() -> impl IntoView { let timestamp = use_timestamp(); view! { -
Timestamp: {timestamp}
+
+ Timestamp: + {timestamp} +
} } diff --git a/examples/use_websocket/Cargo.toml b/examples/use_websocket/Cargo.toml index 7f93ca1..64de6b0 100644 --- a/examples/use_websocket/Cargo.toml +++ b/examples/use_websocket/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_websocket/src/main.rs b/examples/use_websocket/src/main.rs index f05af76..d7fef69 100644 --- a/examples/use_websocket/src/main.rs +++ b/examples/use_websocket/src/main.rs @@ -30,8 +30,8 @@ fn Demo() -> impl IntoView { } = use_websocket("wss://echo.websocket.events/"); let send_message = move |_| { - let m = "Hello, world!".to_string(); - send(m.clone()); + let m = "Hello, world!"; + send(m); set_history.update(|history: &mut Vec<_>| history.push(format! {"[send]: {:?}", m})); }; @@ -125,8 +125,8 @@ fn Demo() -> impl IntoView { }; let send_message2 = move |_| { - let message = "Hello, use_leptos!".to_string(); - send2(message.clone()); + let message = "Hello, use_leptos!"; + send2(message); update_history(&set_history2, format! {"[send]: {:?}", message}); }; @@ -182,10 +182,10 @@ fn Demo() -> impl IntoView { {message} } - } - /> + let:item + > +
{item.1}
+
@@ -216,11 +216,10 @@ fn Demo() -> impl IntoView { {message} } - } - /> - + let:item + > +
  • {item.1}
  • +
    diff --git a/examples/use_window_focus/Cargo.toml b/examples/use_window_focus/Cargo.toml index c75ee5d..611a50e 100644 --- a/examples/use_window_focus/Cargo.toml +++ b/examples/use_window_focus/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_window_scroll/Cargo.toml b/examples/use_window_scroll/Cargo.toml index 32ecc14..bdaf522 100644 --- a/examples/use_window_scroll/Cargo.toml +++ b/examples/use_window_scroll/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/watch_debounced/Cargo.toml b/examples/watch_debounced/Cargo.toml index 5ce8bcd..c088b01 100644 --- a/examples/watch_debounced/Cargo.toml +++ b/examples/watch_debounced/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/watch_pausable/Cargo.toml b/examples/watch_pausable/Cargo.toml index 40d21fc..50586e8 100644 --- a/examples/watch_pausable/Cargo.toml +++ b/examples/watch_pausable/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/watch_throttled/Cargo.toml b/examples/watch_throttled/Cargo.toml index 8852c4f..7d03eb4 100644 --- a/examples/watch_throttled/Cargo.toml +++ b/examples/watch_throttled/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.5.0-rc2", features = ["nightly", "csr"] } +leptos = { version = "0.5", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/src/docs/boolean_display.rs b/src/docs/boolean_display.rs index 3fbba42..33322d6 100644 --- a/src/docs/boolean_display.rs +++ b/src/docs/boolean_display.rs @@ -18,8 +18,5 @@ pub fn BooleanDisplay( ) }; - view! { - { move || if value.get() { true_str} else { false_str } } - - } + view! { {move || if value.get() { true_str } else { false_str }} } } diff --git a/src/docs/note.rs b/src/docs/note.rs index a0c4b87..356e62f 100644 --- a/src/docs/note.rs +++ b/src/docs/note.rs @@ -4,6 +4,5 @@ use leptos::*; pub fn Note(#[prop(optional, into)] class: String, children: Children) -> impl IntoView { let class = format!("note {class}"); - view! {
    { children() }
    - } + view! {
    {children()}
    } } diff --git a/src/use_breakpoints.rs b/src/use_breakpoints.rs index 8457d1c..578c15f 100644 --- a/src/use_breakpoints.rs +++ b/src/use_breakpoints.rs @@ -251,15 +251,27 @@ impl UseBreakpointsReturn { /// Reactive Vec of all breakpoints that fulfill `[screen size]` >= `key` pub fn current(&self) -> Signal> { - let this = self.clone(); + let breakpoints = self.breakpoints.clone(); + let keys: Vec<_> = breakpoints.keys().cloned().collect(); - Signal::derive(move || { - this.breakpoints - .keys() - .filter(|k| this.ge((**k).clone()).get()) + let ge = move |key: &K| { + let value = breakpoints + .get(key) + .expect("only used with keys() from the HashMap"); + + use_media_query(format_media_query!("min", =, value)) + }; + + let signals: Vec<_> = keys.iter().map(ge.clone()).collect(); + + create_memo(move |_| { + keys.iter() .cloned() + .zip(signals.iter().cloned()) + .filter_map(|(key, signal)| signal.get().then_some(key)) .collect::>() }) + .into() } } diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 98ffcf4..c50d308 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -39,7 +39,7 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// } = use_websocket("wss://echo.websocket.events/"); /// /// let send_message = move |_| { -/// send("Hello, world!".to_string()); +/// send("Hello, world!"); /// }; /// /// let send_byte_message = move |_| { @@ -67,8 +67,8 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// /// /// -///

    "Receive message: " {format! {"{:?}", message}}

    -///

    "Receive byte message: " {format! {"{:?}", message_bytes}}

    +///

    "Receive message: " {move || format!("{:?}", message.get())}

    +///

    "Receive byte message: " {move || format!("{:?}", message_bytes.get())}

    /// /// } /// # } @@ -87,6 +87,106 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// | https://example.com/some/where | //otherdomain.com/api/ws | wss://otherdomain.com/api/ws | /// /// +/// ## Usage with `provide_context` +/// +/// The return value of `use_websocket` utilizes several type parameters which can make it +/// cumbersome to use with `provide_context` + `expect_context`. +/// The following example shows how to avoid type parameters with dynamic dispatch. +/// This sacrifices a little bit of performance for the sake of ergonomics. However, +/// compared to network transmission speeds this loss of performance is negligible. +/// +/// First we define the `struct` that is going to be passed around as context. +/// +/// ``` +/// # use leptos::*; +/// use std::rc::Rc; +/// +/// #[derive(Clone)] +/// pub struct WebsocketContext { +/// pub message: Signal>, +/// send: Rc, // use Rc to make it easily cloneable +/// } +/// +/// impl WebsocketContext { +/// pub fn new(message: Signal>, send: Rc) -> Self { +/// Self { +/// message, +/// send, +/// } +/// } +/// +/// // create a method to avoid having to use parantheses around the field +/// #[inline(always)] +/// pub fn send(&self, message: &str) { +/// (self.send)(message) +/// } +/// } +/// ``` +/// +/// Now you can provide the context like the following. +/// +/// ``` +/// # use leptos::*; +/// # use leptos_use::{use_websocket, UseWebsocketReturn}; +/// # use std::rc::Rc; +/// # #[derive(Clone)] +/// # pub struct WebsocketContext { +/// # pub message: Signal>, +/// # send: Rc, +/// # } +/// # +/// # impl WebsocketContext { +/// # pub fn new(message: Signal>, send: Rc) -> Self { +/// # Self { +/// # message, +/// # send, +/// # } +/// # } +/// # } +/// +/// # #[component] +/// # fn Demo() -> impl IntoView { +/// let UseWebsocketReturn { +/// message, +/// send, +/// .. +/// } = use_websocket("ws:://some.websocket.io"); +/// +/// provide_context(WebsocketContext::new(message, Rc::new(send.clone()))); +/// # +/// # view! {} +/// # } +/// ``` +/// +/// Finally let's use the context: +/// +/// ``` +/// # use leptos::*; +/// # use leptos_use::{use_websocket, UseWebsocketReturn}; +/// # use std::rc::Rc; +/// # #[derive(Clone)] +/// # pub struct WebsocketContext { +/// # pub message: Signal>, +/// # send: Rc, +/// # } +/// # +/// # impl WebsocketContext { +/// # #[inline(always)] +/// # pub fn send(&self, message: &str) { +/// # (self.send)(message) +/// # } +/// # } +/// +/// # #[component] +/// # fn Demo() -> impl IntoView { +/// let websocket = expect_context::(); +/// +/// websocket.send("Hello World!"); +/// # +/// # view! {} +/// # } +/// ``` +/// /// ## Server-Side Rendering /// /// On the server the returned functions amount to no-ops. @@ -95,7 +195,7 @@ pub fn use_websocket( ) -> UseWebsocketReturn< impl Fn() + Clone + 'static, impl Fn() + Clone + 'static, - impl Fn(String) + Clone + 'static, + impl Fn(&str) + Clone + 'static, impl Fn(Vec) + Clone + 'static, > { use_websocket_with_options(url, UseWebSocketOptions::default()) @@ -108,7 +208,7 @@ pub fn use_websocket_with_options( ) -> UseWebsocketReturn< impl Fn() + Clone + 'static, impl Fn() + Clone + 'static, - impl Fn(String) + Clone + 'static, + impl Fn(&str) + Clone + 'static, impl Fn(Vec) + Clone, > { let url = normalize_url(url); @@ -302,10 +402,10 @@ pub fn use_websocket_with_options( // Send text (String) let send = { - Box::new(move |data: String| { + Box::new(move |data: &str| { if ready_state.get() == ConnectionReadyState::Open { if let Some(web_socket) = ws_ref.get_value() { - let _ = web_socket.send_with_str(&data); + let _ = web_socket.send_with_str(data); } } }) @@ -412,7 +512,7 @@ pub struct UseWebsocketReturn where OpenFn: Fn() + Clone + 'static, CloseFn: Fn() + Clone + 'static, - SendFn: Fn(String) + Clone + 'static, + SendFn: Fn(&str) + Clone + 'static, SendBytesFn: Fn(Vec) + Clone + 'static, { /// The current state of the `WebSocket` connection.