From 2e08874db08e9fb98afdb2b26cd08c06df11f8e3 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Thu, 27 Jul 2023 18:06:36 +0100 Subject: [PATCH] ported to leptos 0.5 alpha --- .idea/icon.svg | 13 ++- .idea/leptos-use.iml | 4 + CHANGELOG.md | 3 + Cargo.toml | 6 +- README.md | 5 +- docs/book/src/SUMMARY.md | 5 + docs/book/src/get_started.md | 4 +- docs/book/src/server_side_rendering.md | 2 +- examples/Cargo.toml | 2 + examples/on_click_outside/Cargo.toml | 2 +- examples/on_click_outside/src/main.rs | 17 ++- examples/signal_debounced/Cargo.toml | 2 +- examples/signal_debounced/src/main.rs | 12 +- examples/signal_throttled/Cargo.toml | 2 +- examples/signal_throttled/src/main.rs | 12 +- examples/ssr/Cargo.toml | 10 +- examples/ssr/src/app.rs | 31 +++-- examples/ssr/src/error_template.rs | 13 +-- examples/ssr/src/fileserv.rs | 2 +- examples/ssr/src/lib.rs | 4 +- examples/ssr/src/main.rs | 4 +- examples/use_abs/Cargo.toml | 2 +- examples/use_abs/src/main.rs | 13 +-- examples/use_active_element/Cargo.toml | 2 +- examples/use_active_element/src/main.rs | 17 ++- examples/use_breakpoints/Cargo.toml | 2 +- examples/use_breakpoints/src/main.rs | 11 +- examples/use_ceil/Cargo.toml | 2 +- examples/use_ceil/src/main.rs | 13 +-- examples/use_color_mode/Cargo.toml | 2 +- examples/use_color_mode/src/main.rs | 13 +-- examples/use_css_var/Cargo.toml | 2 +- examples/use_css_var/src/main.rs | 19 ++-- examples/use_cycle_list/Cargo.toml | 2 +- examples/use_cycle_list/src/main.rs | 18 ++- examples/use_debounce_fn/Cargo.toml | 2 +- examples/use_debounce_fn/src/main.rs | 13 +-- examples/use_document_visibility/Cargo.toml | 2 +- examples/use_document_visibility/src/main.rs | 47 ++++---- examples/use_draggable/Cargo.toml | 2 +- examples/use_draggable/src/main.rs | 12 +- examples/use_drop_zone/Cargo.toml | 2 +- examples/use_drop_zone/src/main.rs | 19 ++-- examples/use_element_hover/Cargo.toml | 2 +- examples/use_element_hover/src/main.rs | 12 +- examples/use_element_size/Cargo.toml | 2 +- examples/use_element_size/src/main.rs | 13 +-- examples/use_element_visibility/Cargo.toml | 2 +- examples/use_element_visibility/src/main.rs | 13 +-- examples/use_event_listener/Cargo.toml | 2 +- examples/use_event_listener/src/main.rs | 21 ++-- examples/use_favicon/Cargo.toml | 2 +- examples/use_favicon/src/main.rs | 15 +-- examples/use_floor/Cargo.toml | 2 +- examples/use_floor/src/main.rs | 13 +-- examples/use_intersection_observer/Cargo.toml | 2 +- .../use_intersection_observer/src/main.rs | 16 ++- examples/use_interval/Cargo.toml | 2 +- examples/use_interval/src/main.rs | 11 +- examples/use_interval_fn/Cargo.toml | 2 +- examples/use_interval_fn/src/main.rs | 24 ++-- examples/use_intl_number_format/Cargo.toml | 2 +- examples/use_intl_number_format/src/main.rs | 17 ++- examples/use_media_query/Cargo.toml | 2 +- examples/use_media_query/src/main.rs | 13 +-- examples/use_mouse/Cargo.toml | 2 +- examples/use_mouse/src/main.rs | 14 +-- examples/use_mutation_observer/Cargo.toml | 2 +- examples/use_mutation_observer/src/main.rs | 25 ++--- examples/use_raf_fn/Cargo.toml | 2 +- examples/use_raf_fn/src/main.rs | 13 +-- examples/use_resize_observer/Cargo.toml | 2 +- examples/use_resize_observer/src/main.rs | 15 ++- examples/use_round/Cargo.toml | 2 +- examples/use_round/src/main.rs | 13 +-- examples/use_scroll/Cargo.toml | 2 +- examples/use_scroll/src/main.rs | 32 +++--- examples/use_storage/Cargo.toml | 2 +- examples/use_storage/src/main.rs | 15 ++- examples/use_throttle_fn/Cargo.toml | 2 +- examples/use_throttle_fn/src/main.rs | 18 +-- examples/use_websocket/Cargo.toml | 2 +- examples/use_websocket/src/main.rs | 32 +++--- examples/use_window_focus/Cargo.toml | 2 +- examples/use_window_focus/src/main.rs | 33 +++--- examples/use_window_scroll/Cargo.toml | 2 +- examples/use_window_scroll/src/main.rs | 11 +- examples/watch_debounced/Cargo.toml | 2 +- examples/watch_debounced/src/main.rs | 14 +-- examples/watch_pausable/Cargo.toml | 2 +- examples/watch_pausable/src/main.rs | 16 ++- examples/watch_throttled/Cargo.toml | 2 +- examples/watch_throttled/src/main.rs | 14 +-- src/core/element_maybe_signal.rs | 55 ++++----- src/core/elements_maybe_signal.rs | 106 ++++++++---------- src/core/maybe_rw_signal.rs | 8 +- src/docs/boolean_display.rs | 4 +- src/docs/note.rs | 5 +- src/is_err.rs | 7 +- src/is_none.rs | 7 +- src/is_ok.rs | 7 +- src/is_some.rs | 7 +- src/math/shared.rs | 8 +- src/math/use_abs.rs | 8 +- src/math/use_ceil.rs | 8 +- src/math/use_floor.rs | 8 +- src/math/use_max.rs | 8 +- src/math/use_min.rs | 8 +- src/math/use_round.rs | 8 +- src/on_click_outside.rs | 21 ++-- src/signal_debounced.rs | 15 ++- src/signal_throttled.rs | 15 ++- src/storage/shared.rs | 6 +- src/storage/use_storage.rs | 39 +++---- src/use_active_element.rs | 20 ++-- src/use_breakpoints.rs | 30 +++-- src/use_color_mode.rs | 57 ++++------ src/use_css_var.rs | 44 ++++---- src/use_cycle_list.rs | 20 +--- src/use_debounce_fn.rs | 8 +- src/use_document_visibility.rs | 12 +- src/use_draggable.rs | 47 ++++---- src/use_drop_zone.rs | 30 +++-- src/use_element_hover.rs | 29 ++--- src/use_element_size.rs | 25 ++--- src/use_element_visibility.rs | 25 ++--- src/use_event_listener.rs | 42 +++---- src/use_favicon.rs | 25 ++--- src/use_intersection_observer.rs | 29 ++--- src/use_interval.rs | 13 +-- src/use_interval_fn.rs | 16 +-- src/use_intl_number_format.rs | 77 +++++++------ src/use_media_query.rs | 19 ++-- src/use_mouse.rs | 52 ++++----- src/use_mutation_observer.rs | 24 ++-- src/use_preferred_contrast.rs | 16 +-- src/use_preferred_dark.rs | 10 +- src/use_raf_fn.rs | 20 ++-- src/use_resize_observer.rs | 27 ++--- src/use_scroll.rs | 101 +++++++---------- src/use_supported.rs | 9 +- src/use_throttle_fn.rs | 8 +- src/use_to_string.rs | 8 +- src/use_websocket.rs | 42 ++++--- src/use_window_focus.rs | 14 +-- src/use_window_scroll.rs | 15 ++- src/utils/filters/pausable.rs | 3 +- src/utils/signal_filtered.rs | 8 +- src/utils/use_derive_signal.rs | 4 +- src/watch_debounced.rs | 27 ++--- src/watch_pausable.rs | 15 +-- src/watch_throttled.rs | 28 ++--- src/watch_with_options.rs | 29 ++--- src/whenever.rs | 37 +++--- template/.ffizer.yaml | 5 - .../src/main.ffizer.hbs.rs | 11 +- .../{{ function_name }}.ffizer.hbs.rs | 12 +- 157 files changed, 1026 insertions(+), 1280 deletions(-) diff --git a/.idea/icon.svg b/.idea/icon.svg index fb9d78d..09f8e86 100644 --- a/.idea/icon.svg +++ b/.idea/icon.svg @@ -2,6 +2,17 @@ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> + + style="fill-rule:nonzero;"/> \ No newline at end of file diff --git a/.idea/leptos-use.iml b/.idea/leptos-use.iml index 9a57ee7..e4cba54 100644 --- a/.idea/leptos-use.iml +++ b/.idea/leptos-use.iml @@ -48,6 +48,10 @@ + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index c925260..b21db9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Braking Changes 🛠 +- Leptos version is now 0.5 +- No `cx: Scope` params are supported/needed anymore because of the changes in Leptos. + Please check the release notes of Leptos 0.5 for how to upgrade. - `watch` is now deprecated in favor of `leptos::watch`. `watch_with_options` will continue to exist. diff --git a/Cargo.toml b/Cargo.toml index 213d0ae..6ba2f57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-use" -version = "0.6.0" +version = "0.7.0-alpha" 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.4" +leptos = "0.5.0-alpha" wasm-bindgen = "0.2" js-sys = "0.3" default-struct-builder = "0.4" @@ -80,5 +80,3 @@ all-features = true rustdoc-args = ["--cfg=web_sys_unstable_apis"] rustc-args = ["--cfg=web_sys_unstable_apis"] -[dev-dependencies] -leptos = "0.4" diff --git a/README.md b/README.md index a70e763..75c44b4 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ use leptos::*; use leptos_use::{use_mouse, UseMouseReturn}; #[component] -fn Demo(cx: Scope) -> impl IntoView { - let UseMouseReturn { x, y, .. } = use_mouse(cx); +fn Demo() -> impl IntoView { + let UseMouseReturn { x, y, .. } = use_mouse(); view! { cx, {x} " x " {y} @@ -89,3 +89,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 | diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 0542b5d..5f40d76 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -62,6 +62,11 @@ - [watch_with_options](watch/watch_with_options.md) - [whenever](watch/whenever.md) +# Reactivity + +- [signal_debounced](reactivity/signal_debounced.md) +- [signal_throttled](reactivity/signal_throttled.md) + # Utilities - [is_err](utilities/is_err.md) diff --git a/docs/book/src/get_started.md b/docs/book/src/get_started.md index 46cc788..9a40e34 100644 --- a/docs/book/src/get_started.md +++ b/docs/book/src/get_started.md @@ -19,8 +19,8 @@ use leptos::*; use leptos_use::{use_mouse, UseMouseReturn}; #[component] -fn Demo(cx: Scope) -> impl IntoView { - let UseMouseReturn { x, y, .. } = use_mouse(cx); +fn Demo() -> impl IntoView { + let UseMouseReturn { x, y, .. } = use_mouse(); view! { cx, {x} " x " {y} diff --git a/docs/book/src/server_side_rendering.md b/docs/book/src/server_side_rendering.md index ace770e..8f16416 100644 --- a/docs/book/src/server_side_rendering.md +++ b/docs/book/src/server_side_rendering.md @@ -41,7 +41,7 @@ create_effect( cx, move |_| { // window() doesn't work on the server - use_event_listener(cx, window(), "resize", move |_| { + use_event_listener(window(), "resize", move |_| { // ... }) }, diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e238422..4c3dec2 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -3,6 +3,8 @@ resolver = "2" members = [ "on_click_outside", + "signal_debounced", + "signal_throttled", "use_abs", "use_active_element", "use_breakpoints", diff --git a/examples/on_click_outside/Cargo.toml b/examples/on_click_outside/Cargo.toml index 6a27995..a055bb2 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.4", features = ["nightly", "csr"] } +leptos = { version = "0.5.0-alpha", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/on_click_outside/src/main.rs b/examples/on_click_outside/src/main.rs index 93ee27a..6571e51 100644 --- a/examples/on_click_outside/src/main.rs +++ b/examples/on_click_outside/src/main.rs @@ -4,16 +4,15 @@ use leptos_use::docs::demo_or_body; use leptos_use::on_click_outside; #[component] -fn Demo(cx: Scope) -> impl IntoView { - let (show_modal, set_show_modal) = create_signal(cx, false); - let modal_ref = create_node_ref::
(cx); +fn Demo() -> impl IntoView { + let (show_modal, set_show_modal) = create_signal(false); + let modal_ref = create_node_ref::
(); - let _ = on_click_outside(cx, modal_ref, move |_| set_show_modal.set(false)); + let _ = on_click_outside(modal_ref, move |_| set_show_modal.set(false)); - view! { cx, - + view! { - +