From ada0c27d712a2a79dffafecb6b3a29a94bcf6144 Mon Sep 17 00:00:00 2001
From: Jens Krause <email@jkrause.io>
Date: Thu, 13 Jul 2023 08:04:01 +0200
Subject: [PATCH] Fix callback handling of `use_scroll`

by bumping `default-struct-builder`
---
 Cargo.toml                      |  2 +-
 examples/use_scroll/src/main.rs | 15 ++++++++++++++-
 src/use_scroll.rs               |  8 +++-----
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 1e77af5..80cc532 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ homepage = "https://leptos-use.rs"
 leptos = "0.4"
 wasm-bindgen = "0.2"
 js-sys = "0.3"
-default-struct-builder = "0.3"
+default-struct-builder = "0.4"
 num = { version = "0.4", optional = true }
 serde = { version = "1", optional = true }
 serde_json = { version = "1", optional = true }
diff --git a/examples/use_scroll/src/main.rs b/examples/use_scroll/src/main.rs
index 23e7ac6..898e3a6 100644
--- a/examples/use_scroll/src/main.rs
+++ b/examples/use_scroll/src/main.rs
@@ -3,6 +3,8 @@ use leptos::*;
 use leptos_use::docs::{demo_or_body, BooleanDisplay};
 use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn};
 
+use web_sys::Event;
+
 #[component]
 fn Demo(cx: Scope) -> impl IntoView {
     let el = create_node_ref::<Div>(cx);
@@ -24,7 +26,18 @@ fn Demo(cx: Scope) -> impl IntoView {
         arrived_state,
         directions,
         ..
-    } = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior));
+    } = use_scroll_with_options(
+        cx,
+        el,
+        UseScrollOptions::default()
+            .behavior(behavior)
+            .on_stop(move |_: Event| {
+                log!("scrolling stopped");
+            })
+            .on_scroll(move |_: Event| {
+                log!("scrolling");
+            }),
+    );
 
     view! { cx,
         <div class="flex">
diff --git a/src/use_scroll.rs b/src/use_scroll.rs
index e22bff1..3576218 100644
--- a/src/use_scroll.rs
+++ b/src/use_scroll.rs
@@ -1,6 +1,6 @@
 use crate::core::ElementMaybeSignal;
 use crate::use_event_listener::use_event_listener_with_options;
-use crate::utils::CloneableFnWithArg;
+use crate::utils::CloneableFnMutWithArg;
 use crate::{use_debounce_fn_with_arg, use_throttle_fn_with_arg_and_options, ThrottleOptions};
 use default_struct_builder::DefaultBuilder;
 use leptos::ev::EventDescriptor;
@@ -456,12 +456,10 @@ pub struct UseScrollOptions {
     offset: ScrollOffset,
 
     /// Callback when scrolling is happening.
-    #[builder(into)]
-    on_scroll: Box<dyn CloneableFnWithArg<web_sys::Event>>,
+    on_scroll: Box<dyn CloneableFnMutWithArg<web_sys::Event> + 'static>,
 
     /// Callback when scrolling stops (after `idle` + `throttle` milliseconds have passed).
-    #[builder(into)]
-    on_stop: Box<dyn CloneableFnWithArg<web_sys::Event>>,
+    on_stop: Box<dyn CloneableFnMutWithArg<web_sys::Event> + 'static>,
 
     /// Options passed to the `addEventListener("scroll", ...)` call
     event_listener_options: web_sys::AddEventListenerOptions,