From c6005079e12c4e55b9042623291d6aec610a12e1 Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Fri, 26 Jul 2024 10:18:09 +0100
Subject: [PATCH 01/17] fixed signal out of scope issue with use_raf_fn.
Fixes #135
---
CHANGELOG.md | 1 +
src/use_raf_fn.rs | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0bf1185..c1c06a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed auto-reconnect in `use_websocket`
- Fixed typo in compiler error messages in `use_cookie` (thanks to @SleeplessOne1917).
+- Fixed potential signal out of scope issue with `use_raf_fn`
## [0.10.10] - 2024-05-10
diff --git a/src/use_raf_fn.rs b/src/use_raf_fn.rs
index a5010db..d390cd1 100644
--- a/src/use_raf_fn.rs
+++ b/src/use_raf_fn.rs
@@ -89,7 +89,7 @@ pub fn use_raf_fn_with_options(
let previous_frame_timestamp = Cell::new(0.0_f64);
move |timestamp: f64| {
- if !is_active.get_untracked() {
+ if !is_active.try_get_untracked().unwrap_or_default() {
return;
}
From ffd4f0a6fe97b83fea126d8257e9541d1cddc6f7 Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Fri, 26 Jul 2024 10:36:39 +0100
Subject: [PATCH 02/17] fixed compile error with use_storage
---
CHANGELOG.md | 3 ++-
src/storage/use_storage.rs | 18 +++++++++++-------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1c06a3..d9734c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,8 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `JsonCodec` has been renamed to `JsonSerdeCodec`.
- The feature to enable this codec is now called `json_serde` instead of just `serde`.
- `ProstCodec` now encodes as binary data. If you want to keep using it with string data you can wrap it like
- this: `Base64`. You have to enable both features `prost` and `base64` for this.
+ this: `Base64`.
- All of these structs, traits and features now live in their own crate called `codee`
+ - A bunch of new codecs are available. Have a look at the docs for crate `codee`.
- `use_websocket`:
- `UseWebsocketOptions` has been renamed to `UseWebSocketOptions` (uppercase S) to be consistent with the return
type.
diff --git a/src/storage/use_storage.rs b/src/storage/use_storage.rs
index 1c31fea..73eaa35 100644
--- a/src/storage/use_storage.rs
+++ b/src/storage/use_storage.rs
@@ -276,13 +276,17 @@ where
let notify = create_trigger();
// Refetch from storage. Keeps track of how many times we've been notified. Does not increment for calls to set_data
- let notify_id = create_memo::(move |prev| {
- notify.track();
- match prev {
- None => 1, // Avoid async fetch of initial value
- Some(prev) => {
- fetch_from_storage();
- prev + 1
+ let notify_id = create_memo::({
+ let fetch_from_storage = fetch_from_storage.clone();
+
+ move |prev| {
+ notify.track();
+ match prev {
+ None => 1, // Avoid async fetch of initial value
+ Some(prev) => {
+ fetch_from_storage();
+ prev + 1
+ }
}
}
});
From 17cfb8a23bb99ff6c815131b1772de71271ea0a8 Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Fri, 26 Jul 2024 10:56:39 +0100
Subject: [PATCH 03/17] clarified read option docs for use_clipboard.
Closes #119
---
.idea/leptos-use.iml | 1 +
examples/use_clipboard/src/main.rs | 6 ++++--
src/use_clipboard.rs | 2 ++
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.idea/leptos-use.iml b/.idea/leptos-use.iml
index 7d56fcb..b65a8a2 100644
--- a/.idea/leptos-use.iml
+++ b/.idea/leptos-use.iml
@@ -77,6 +77,7 @@
+
diff --git a/examples/use_clipboard/src/main.rs b/examples/use_clipboard/src/main.rs
index e7852b3..ebfbf63 100644
--- a/examples/use_clipboard/src/main.rs
+++ b/examples/use_clipboard/src/main.rs
@@ -1,6 +1,8 @@
use leptos::*;
use leptos_use::docs::{demo_or_body, Note};
-use leptos_use::{use_clipboard, use_permission, UseClipboardReturn};
+use leptos_use::{
+ use_clipboard_with_options, use_permission, UseClipboardOptions, UseClipboardReturn,
+};
#[component]
fn Demo() -> impl IntoView {
@@ -11,7 +13,7 @@ fn Demo() -> impl IntoView {
text,
copied,
copy,
- } = use_clipboard();
+ } = use_clipboard_with_options(UseClipboardOptions::default().read(true));
let permission_read = use_permission("clipboard-read");
let permission_write = use_permission("clipboard-write");
diff --git a/src/use_clipboard.rs b/src/use_clipboard.rs
index 78c7eb9..2d4ab26 100644
--- a/src/use_clipboard.rs
+++ b/src/use_clipboard.rs
@@ -127,6 +127,8 @@ pub fn use_clipboard_with_options(
pub struct UseClipboardOptions {
/// When `true` event handlers are added so that the returned signal `text` is updated whenever the clipboard changes.
/// Defaults to `false`.
+ ///
+ /// > Please note that clipboard changes are only detected when copying or cutting text inside the same document.
read: bool,
/// After how many milliseconds after copying should the returned signal `copied` be set to `false`?
From e21ed8ec31560414fa93a1310ff77fbb6168b745 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?=
Date: Sat, 27 Jul 2024 18:10:38 +0200
Subject: [PATCH 04/17] Make rustdocs links work with the book
---
docs/book/post_build.py | 26 ++++++++++++++++-
src/core/element_maybe_signal.rs | 2 +-
src/core/elements_maybe_signal.rs | 2 +-
src/storage/use_local_storage.rs | 11 +++++--
src/storage/use_session_storage.rs | 4 +--
src/storage/use_storage.rs | 8 ++---
src/use_breakpoints.rs | 47 +++++++++++++++---------------
src/use_broadcast_channel.rs | 2 +-
src/use_color_mode.rs | 16 +++++-----
src/use_cookie.rs | 6 +---
src/use_element_size.rs | 2 +-
src/use_element_visibility.rs | 2 +-
src/use_event_source.rs | 6 +---
src/use_intersection_observer.rs | 2 +-
src/use_intl_number_format.rs | 2 +-
src/use_media_query.rs | 4 +--
src/use_preferred_contrast.rs | 4 +--
src/use_preferred_dark.rs | 4 +--
src/use_raf_fn.rs | 2 +-
src/use_resize_observer.rs | 2 +-
src/use_timestamp.rs | 4 +--
src/use_websocket.rs | 1 +
src/use_window.rs | 2 +-
src/utils/use_derive_signal.rs | 2 +-
src/watch_debounced.rs | 9 +++---
src/watch_pausable.rs | 2 +-
src/watch_throttled.rs | 8 ++---
src/watch_with_options.rs | 7 +++--
src/whenever.rs | 6 ++--
29 files changed, 110 insertions(+), 85 deletions(-)
diff --git a/docs/book/post_build.py b/docs/book/post_build.py
index 1abc3a2..fc9fc3a 100644
--- a/docs/book/post_build.py
+++ b/docs/book/post_build.py
@@ -14,6 +14,7 @@ def main():
for file in os.listdir(category_dir):
if file.endswith(".md") and (len(sys.argv) == 1 or (sys.argv[1] in file)):
build_and_copy_demo(category, file)
+ rewrite_links(category, file)
def build_and_copy_demo(category, md_name):
@@ -24,7 +25,8 @@ def build_and_copy_demo(category, md_name):
code = p.wait()
if code != 0:
- sys.exit(code, f"failed to build example '{name}'")
+ sys.stderr.write(f"failed to build example '{name}'\n")
+ sys.exit(code)
example_output_path = os.path.join(example_dir, "dist")
target_path = os.path.join("book", category, name, "demo")
@@ -61,5 +63,27 @@ def build_and_copy_demo(category, md_name):
{body_split[1]}""")
+def rewrite_links(category, md_name):
+ """Rewrite links in generated documentation to make them
+ compatible between rustdoc and the book.
+ """
+ html_name = f"{md_name[:-3]}.html"
+ target_path = os.path.join("book", category, html_name)
+
+ with open(target_path, "r") as f:
+ html = f.read()
+
+ html = html.replace(
+ "fn@crate::", "",
+ ).replace(
+ "crate::", "",
+ ).replace(
+ "fn@", "",
+ )
+
+ with open(target_path, "w") as f:
+ f.write(html)
+
+
if __name__ == '__main__':
main()
diff --git a/src/core/element_maybe_signal.rs b/src/core/element_maybe_signal.rs
index 26c1216..6d25d41 100644
--- a/src/core/element_maybe_signal.rs
+++ b/src/core/element_maybe_signal.rs
@@ -11,7 +11,7 @@ use std::ops::Deref;
/// * a `Signal` where `T` is the web_sys element,
/// * a `Signal
@@ -92,4 +92,4 @@ This will create the function file in the src directory, scaffold an example dir
| <= 0.3 | 0.3 |
| 0.4, 0.5, 0.6 | 0.4 |
| 0.7, 0.8, 0.9 | 0.5 |
-| 0.10 | 0.6 |
\ No newline at end of file
+| 0.10, 0.11 | 0.6 |
diff --git a/docs/book/src/introduction.md b/docs/book/src/introduction.md
index f12ec1b..cf0098a 100644
--- a/docs/book/src/introduction.md
+++ b/docs/book/src/introduction.md
@@ -12,6 +12,6 @@
-
+
\ No newline at end of file
diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml
index d0b6e6a..5d71626 100644
--- a/examples/ssr/Cargo.toml
+++ b/examples/ssr/Cargo.toml
@@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
axum = { version = "0.7", optional = true }
+codee = "0.1"
console_error_panic_hook = "0.1"
console_log = "1"
cfg-if = "1"
diff --git a/examples/ssr/src/app.rs b/examples/ssr/src/app.rs
index 80b8695..7db0793 100644
--- a/examples/ssr/src/app.rs
+++ b/examples/ssr/src/app.rs
@@ -4,7 +4,7 @@ use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use leptos_use::storage::{use_local_storage, use_local_storage_with_options, UseStorageOptions};
-use leptos_use::utils::FromToStringCodec;
+use codee::string::FromToStringCodec;
use leptos_use::{
use_color_mode_with_options, use_cookie_with_options, use_debounce_fn, use_event_listener,
use_interval, use_intl_number_format, use_preferred_dark, use_timestamp, use_window, ColorMode,
@@ -78,7 +78,7 @@ fn HomePage() -> impl IntoView {
let (test_cookie, _) = use_cookie_with_options::(
"test-cookie",
- UseCookieOptions::::default()
+ UseCookieOptions::::default()
.max_age(3000)
.default_value(Some("Bogus string".to_owned())),
);
diff --git a/src/use_cookie.rs b/src/use_cookie.rs
index 1af6615..d212b18 100644
--- a/src/use_cookie.rs
+++ b/src/use_cookie.rs
@@ -359,6 +359,8 @@ where
#[cfg(feature = "ssr")]
{
if !readonly {
+ let cookie_name = cookie_name.to_owned();
+
create_isomorphic_effect(move |_| {
let value = cookie
.with(|cookie| {
@@ -369,20 +371,27 @@ where
})
})
.flatten();
- jar.update_value(|jar| {
- write_server_cookie(
- cookie_name,
- value,
- jar,
- max_age,
- expires,
- domain,
- path,
- same_site,
- secure,
- http_only,
- ssr_set_cookie,
- )
+
+ jar.update_value({
+ let domain = domain.clone();
+ let path = path.clone();
+ let ssr_set_cookie = Rc::clone(&ssr_set_cookie);
+
+ |jar| {
+ write_server_cookie(
+ &cookie_name,
+ value,
+ jar,
+ max_age,
+ expires,
+ domain,
+ path,
+ same_site,
+ secure,
+ http_only,
+ ssr_set_cookie,
+ )
+ }
});
});
}
From 2fe13f954015b5ab60f5f871ae8d05bf452d35dd Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Sat, 27 Jul 2024 19:17:37 +0100
Subject: [PATCH 14/17] chore: rustfmt
---
src/use_cookie.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/use_cookie.rs b/src/use_cookie.rs
index d212b18..b7773a8 100644
--- a/src/use_cookie.rs
+++ b/src/use_cookie.rs
@@ -360,7 +360,7 @@ where
{
if !readonly {
let cookie_name = cookie_name.to_owned();
-
+
create_isomorphic_effect(move |_| {
let value = cookie
.with(|cookie| {
From c674b45635ddc998b824404c847521fc12b63e67 Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Sat, 27 Jul 2024 19:25:31 +0100
Subject: [PATCH 15/17] fixed tests
---
src/use_clipboard.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/use_clipboard.rs b/src/use_clipboard.rs
index 74a7ff9..c6f1efe 100644
--- a/src/use_clipboard.rs
+++ b/src/use_clipboard.rs
@@ -29,14 +29,14 @@ use leptos::*;
///
/// view! {
/// Your browser does not support Clipboard API }
/// >
///
From c64fb046f8e2ba46e89118453cdb2775f1dc17b1 Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Sat, 27 Jul 2024 19:45:42 +0100
Subject: [PATCH 16/17] updated readme build batch
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7711119..052d738 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@
[![Docs](https://docs.rs/leptos-use/badge.svg)](https://docs.rs/leptos-use/)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/synphonyte/leptos-use#license)
-[![Build Status](https://github.com/synphonyte/leptos-use/actions/workflows/ci.yml/badge.svg)](https://github.com/synphonyte/leptos-use/actions/workflows/ci.yml)
+[![Build Status](https://github.com/synphonyte/leptos-use/actions/workflows/cd.yml/badge.svg)](https://github.com/synphonyte/leptos-use/actions/workflows/cd.yml)
[![Discord](https://img.shields.io/discord/1031524867910148188?color=%237289DA&label=discord)](https://discord.com/channels/1031524867910148188/1121154537709895783)
```rust
From 0a8cb7832e2fabde47bb10d4a31859ae791695fb Mon Sep 17 00:00:00 2001
From: Maccesch
Date: Sun, 28 Jul 2024 16:05:23 +0100
Subject: [PATCH 17/17] updated to leptos 0.7 beta
---
Cargo.toml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 016d645..6da9423 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,8 +26,8 @@ http1 = { version = "1", optional = true, package = "http" }
http0_2 = { version = "0.2", optional = true, package = "http" }
js-sys = "0.3"
lazy_static = "1"
-leptos = { version = "0.7.0-alpha" }
-leptos_axum = { version = "0.7.0-alpha", optional = true }
+leptos = { version = "0.7.0-beta" }
+leptos_axum = { version = "0.7.0-beta", optional = true }
leptos_actix = { version = "0.6", optional = true }
leptos-spin = { version = "0.2", optional = true }
num = { version = "0.4", optional = true }
@@ -131,7 +131,7 @@ features = [
[dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
-leptos_meta = "0.7.0-alpha"
+leptos_meta = "0.7.0-beta"
rand = "0.8"
codee = { version = "0.1", features = ["json_serde", "msgpack_serde", "base64", "prost"] }
serde = { version = "1", features = ["derive"] }