mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-22 16:49:22 -05:00
updated docs and changelog
This commit is contained in:
parent
04bcb6b319
commit
074685acab
13 changed files with 107 additions and 39 deletions
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -3,20 +3,27 @@
|
|||
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.13.0] - 2024-08-28
|
||||
|
||||
### New Functions 🚀
|
||||
|
||||
- `use_toggle`
|
||||
- `use_prefers_reduced_motion`
|
||||
- `use_prefers_reduced_motion` (thanks to @hcandelaria)
|
||||
|
||||
### Breaking Change 🛠
|
||||
### Breaking Changes 🛠
|
||||
|
||||
- `use_websocket` now supports different types for sending and receiving messages
|
||||
- `SyncSignalOptions` now can take now either transformations or assignment functions but not both.
|
||||
|
||||
### Change 🔥
|
||||
### Fixes 🍕
|
||||
|
||||
- `use_websocket` fixed error with cleanup and reconnect (thanks to @BakerNet).
|
||||
|
||||
### New Features 🚀
|
||||
|
||||
- There is now a feature for almost every function to get better compile and rust-analyzer times.
|
||||
- `use_web_notification` now supports the `vibrate` option (thanks to @hcandelaria).
|
||||
- `UseDocument` now supports a whole bunch of methods more from `document` (thanks to @luckynumberke7in).
|
||||
|
||||
## [0.12.0] - 2024-08-14
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "leptos-use"
|
||||
version = "0.12.0"
|
||||
version = "0.13.0"
|
||||
edition = "2021"
|
||||
authors = ["Marc-Stefan Cassola"]
|
||||
categories = ["gui", "web-programming"]
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<a href="https://crates.io/crates/leptos-use"><img src="https://img.shields.io/crates/v/leptos-use.svg?label=&color=%232C1275" alt="Crates.io"/></a>
|
||||
<a href="https://leptos-use.rs/server_side_rendering.html"><img src="https://img.shields.io/badge/-SSR-%236a214b" alt="SSR"></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-docs%20%26%20demos-%239A233F" alt="Docs & Demos"></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-82%20functions-%23EF3939" alt="82 Functions" /></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-84%20functions-%23EF3939" alt="84 Functions" /></a>
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
|
@ -88,8 +88,8 @@ This will create the function file in the src directory, scaffold an example dir
|
|||
## Leptos compatibility
|
||||
|
||||
| Crate version | Compatible Leptos version |
|
||||
|------------------|---------------------------|
|
||||
|---------------|---------------------------|
|
||||
| <= 0.3 | 0.3 |
|
||||
| 0.4, 0.5, 0.6 | 0.4 |
|
||||
| 0.7, 0.8, 0.9 | 0.5 |
|
||||
| 0.10, 0.11, 0.12 | 0.6 |
|
||||
| 0.10 – 0.13 | 0.6 |
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
<a href="https://crates.io/crates/leptos-use"><img src="https://img.shields.io/crates/v/leptos-use.svg?label=&color=%232C1275" alt="Crates.io"/></a>
|
||||
<a href="https://leptos-use.rs/server_side_rendering.html"><img src="https://img.shields.io/badge/-SSR-%236a214b" alt="SSR"></a>
|
||||
<a href="./get_started.html"><img src="https://img.shields.io/badge/-docs%20%26%20demos-%239A233F" alt="Docs & Demos"></a>
|
||||
<a href="./functions.html"><img src="https://img.shields.io/badge/-82%20functions-%23EF3939" alt="82 Functions" /></a>
|
||||
<a href="./functions.html"><img src="https://img.shields.io/badge/-84%20functions-%23EF3939" alt="84 Functions" /></a>
|
||||
</p>
|
||||
</div>
|
|
@ -28,8 +28,6 @@ mod is_ok;
|
|||
mod is_some;
|
||||
#[cfg(feature = "on_click_outside")]
|
||||
mod on_click_outside;
|
||||
#[cfg(feature = "use_toggle")]
|
||||
mod use_toggle;
|
||||
#[cfg(feature = "signal_debounced")]
|
||||
mod signal_debounced;
|
||||
#[cfg(feature = "signal_throttled")]
|
||||
|
@ -136,6 +134,8 @@ mod use_timeout_fn;
|
|||
mod use_timestamp;
|
||||
#[cfg(feature = "use_to_string")]
|
||||
mod use_to_string;
|
||||
#[cfg(feature = "use_toggle")]
|
||||
mod use_toggle;
|
||||
#[cfg(feature = "use_user_media")]
|
||||
mod use_user_media;
|
||||
#[cfg(feature = "use_web_notification")]
|
||||
|
@ -169,8 +169,6 @@ pub use is_ok::*;
|
|||
pub use is_some::*;
|
||||
#[cfg(feature = "on_click_outside")]
|
||||
pub use on_click_outside::*;
|
||||
#[cfg(feature = "use_toggle")]
|
||||
pub use use_toggle::*;
|
||||
#[cfg(feature = "signal_debounced")]
|
||||
pub use signal_debounced::*;
|
||||
#[cfg(feature = "signal_throttled")]
|
||||
|
@ -277,6 +275,8 @@ pub use use_timeout_fn::*;
|
|||
pub use use_timestamp::*;
|
||||
#[cfg(feature = "use_to_string")]
|
||||
pub use use_to_string::*;
|
||||
#[cfg(feature = "use_toggle")]
|
||||
pub use use_toggle::*;
|
||||
#[cfg(feature = "use_user_media")]
|
||||
pub use use_user_media::*;
|
||||
#[cfg(feature = "use_web_notification")]
|
||||
|
|
|
@ -7,8 +7,8 @@ use std::rc::Rc;
|
|||
///
|
||||
/// > Note: Please consider first if you can achieve your goals with the
|
||||
/// > ["Good Options" described in the Leptos book](https://book.leptos.dev/reactivity/working_with_signals.html#making-signals-depend-on-each-other)
|
||||
/// > firstly. Only if you really have to, use this function. This is in effect the
|
||||
/// > ["If you really must..."](https://book.leptos.dev/reactivity/working_with_signals.html#if-you-really-must).
|
||||
/// > Only if you really have to, use this function. This is, in effect, the
|
||||
/// > ["If you really must..." option](https://book.leptos.dev/reactivity/working_with_signals.html#if-you-really-must).
|
||||
///
|
||||
/// ## Demo
|
||||
///
|
||||
|
@ -112,9 +112,10 @@ use std::rc::Rc;
|
|||
/// let stop = sync_signal_with_options(
|
||||
/// (a, set_a),
|
||||
/// (b, set_b),
|
||||
/// SyncSignalOptions::default()
|
||||
/// .transform_ltr(|left| *left * 2)
|
||||
/// .transform_rtl(|right| *right / 2)
|
||||
/// SyncSignalOptions::with_transforms(
|
||||
/// |left| *left * 2,
|
||||
/// |right| *right / 2,
|
||||
/// ),
|
||||
/// );
|
||||
///
|
||||
/// logging::log!("a: {}, b: {}", a.get(), b.get()); // a: 10, b: 20
|
||||
|
@ -129,20 +130,60 @@ use std::rc::Rc;
|
|||
///
|
||||
/// #### Different Types
|
||||
///
|
||||
/// `SyncSignalOptions::default()` is only defined if the two signal types are identical or
|
||||
/// implement `From` for each other. Otherwise, you have to initialize the options with
|
||||
/// `with_transforms` instead of `default`.
|
||||
/// `SyncSignalOptions::default()` is only defined if the two signal types are identical.
|
||||
/// Otherwise, you have to initialize the options with `with_transforms` or `with_assigns` instead
|
||||
/// of `default`.
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos_use::SyncSignalOptions;
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::{sync_signal_with_options, SyncSignalOptions};
|
||||
/// # use std::str::FromStr;
|
||||
/// #
|
||||
/// let options = SyncSignalOptions::with_transforms(
|
||||
/// # #[component]
|
||||
/// # fn Demo() -> impl IntoView {
|
||||
/// let (a, set_a) = create_signal("10".to_string());
|
||||
/// let (b, set_b) = create_signal(2);
|
||||
///
|
||||
/// let stop = sync_signal_with_options(
|
||||
/// (a, set_a),
|
||||
/// (b, set_b),
|
||||
/// SyncSignalOptions::with_transforms(
|
||||
/// |left: &String| i32::from_str(left).unwrap_or_default(),
|
||||
/// |right: &i32| right.to_string(),
|
||||
/// ),
|
||||
/// );
|
||||
/// #
|
||||
/// # view! { }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::{sync_signal_with_options, SyncSignalOptions};
|
||||
/// # use std::str::FromStr;
|
||||
/// #
|
||||
/// #[derive(Clone)]
|
||||
/// pub struct Foo {
|
||||
/// bar: i32,
|
||||
/// }
|
||||
///
|
||||
/// # #[component]
|
||||
/// # fn Demo() -> impl IntoView {
|
||||
/// let (a, set_a) = create_signal(Foo { bar: 10 });
|
||||
/// let (b, set_b) = create_signal(2);
|
||||
///
|
||||
/// let stop = sync_signal_with_options(
|
||||
/// (a, set_a),
|
||||
/// (b, set_b),
|
||||
/// SyncSignalOptions::with_assigns(
|
||||
/// |b: &mut i32, a: &Foo| *b = a.bar,
|
||||
/// |a: &mut Foo, b: &i32| a.bar = *b,
|
||||
/// ),
|
||||
/// );
|
||||
/// #
|
||||
/// # view! { }
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn sync_signal<T>(
|
||||
left: impl Into<UseRwSignal<T>>,
|
||||
right: impl Into<UseRwSignal<T>>,
|
||||
|
@ -166,7 +207,7 @@ where
|
|||
let SyncSignalOptions {
|
||||
immediate,
|
||||
direction,
|
||||
transforms
|
||||
transforms,
|
||||
} = options;
|
||||
|
||||
let (assign_ltr, assign_rtl) = transforms.assigns();
|
||||
|
@ -228,13 +269,19 @@ pub enum SyncDirection {
|
|||
|
||||
pub type AssignFn<T, S> = Rc<dyn Fn(&mut T, &S)>;
|
||||
|
||||
/// Transforms or assigns for syncing.
|
||||
pub enum SyncTransforms<L, R> {
|
||||
/// Transform the signal into each other by calling the transform functions.
|
||||
/// The values are then simply assigned.
|
||||
Transforms {
|
||||
/// Transforms the left signal into the right signal.
|
||||
ltr: Rc<dyn Fn(&L) -> R>,
|
||||
/// Transforms the right signal into the left signal.
|
||||
rtl: Rc<dyn Fn(&R) -> L>,
|
||||
},
|
||||
|
||||
/// Assign the signals to each other. Instead of using `=` to assign the signals,
|
||||
/// these functions are called.
|
||||
Assigns {
|
||||
/// Assigns the left signal to the right signal.
|
||||
ltr: AssignFn<R, L>,
|
||||
|
@ -256,13 +303,16 @@ where
|
|||
}
|
||||
|
||||
impl<L, R> SyncTransforms<L, R>
|
||||
where L: 'static, R: 'static
|
||||
where
|
||||
L: 'static,
|
||||
R: 'static,
|
||||
{
|
||||
/// Returns assign functions for both directions that respect the value of this enum.
|
||||
pub fn assigns(&self) -> (AssignFn<R, L>, AssignFn<L, R>) {
|
||||
match self {
|
||||
SyncTransforms::Transforms { ltr, rtl } => {
|
||||
let ltr = Rc::clone(<r);
|
||||
let rtl = Rc::clone(&rtl);
|
||||
let ltr = Rc::clone(ltr);
|
||||
let rtl = Rc::clone(rtl);
|
||||
(
|
||||
Rc::new(move |right, left| *right = ltr(left)),
|
||||
Rc::new(move |left, right| *left = rtl(right)),
|
||||
|
@ -285,13 +335,15 @@ pub struct SyncSignalOptions<L, R> {
|
|||
direction: SyncDirection,
|
||||
|
||||
/// How to transform or assign the values to each other
|
||||
/// Defaults to identity.
|
||||
/// If `L` and `R` are identical this defaults to the simple `=` operator. If the types are
|
||||
/// not the same, then you have to choose to either use [`SyncSignalOptions::with_transforms`]
|
||||
/// or [`SyncSignalOptions::with_assigns`].
|
||||
#[builder(skip)]
|
||||
transforms: SyncTransforms<L, R>,
|
||||
}
|
||||
|
||||
impl<L, R> SyncSignalOptions<L, R> {
|
||||
/// Initializes options with transforms
|
||||
/// Initializes options with transforms functions that convert the signals into each other.
|
||||
pub fn with_transforms(
|
||||
transform_ltr: impl Fn(&L) -> R + 'static,
|
||||
transform_rtl: impl Fn(&R) -> L + 'static,
|
||||
|
@ -306,6 +358,7 @@ impl<L, R> SyncSignalOptions<L, R> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Initializes options with assign functions that replace the default `=` operator.
|
||||
pub fn with_assigns(
|
||||
assign_ltr: impl Fn(&mut R, &L) + 'static,
|
||||
assign_rtl: impl Fn(&mut L, &R) + 'static,
|
||||
|
|
|
@ -4,6 +4,7 @@ use leptos::ev::{copy, cut};
|
|||
use leptos::*;
|
||||
|
||||
/// Reactive [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API).
|
||||
///
|
||||
/// Provides the ability to respond to clipboard commands (cut, copy, and paste)
|
||||
/// as well as to asynchronously read from and write to the system clipboard.
|
||||
/// Access to the contents of the clipboard is gated behind the
|
||||
|
|
|
@ -2,6 +2,7 @@ use cfg_if::cfg_if;
|
|||
use leptos::*;
|
||||
|
||||
/// Reactive [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent).
|
||||
///
|
||||
/// Provide web developers with information from the physical orientation of
|
||||
/// the device running the web page.
|
||||
///
|
||||
|
|
|
@ -13,6 +13,7 @@ cfg_if! { if #[cfg(not(feature = "ssr"))] {
|
|||
}}
|
||||
|
||||
/// Use EventListener with ease.
|
||||
///
|
||||
/// Register using [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) on mounted,
|
||||
/// and [removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener) automatically on cleanup.
|
||||
///
|
||||
|
|
|
@ -3,6 +3,7 @@ use default_struct_builder::DefaultBuilder;
|
|||
use leptos::*;
|
||||
|
||||
/// Reactive [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API).
|
||||
///
|
||||
/// It allows the user to provide their location to web applications if they so desire. For privacy reasons,
|
||||
/// the user is asked for permission to report location information.
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use leptos::*;
|
||||
use crate::core::MaybeRwSignal;
|
||||
use leptos::*;
|
||||
|
||||
/// A boolean switcher with utility functions.
|
||||
///
|
||||
|
@ -25,7 +25,9 @@ use crate::core::MaybeRwSignal;
|
|||
///
|
||||
/// * [`fn@crate::use_cycle_list`]
|
||||
// #[doc(cfg(feature = "use_toggle"))]
|
||||
pub fn use_toggle(initial_value: impl Into<MaybeRwSignal<bool>>) -> UseToggleReturn<impl Fn() + Clone + 'static> {
|
||||
pub fn use_toggle(
|
||||
initial_value: impl Into<MaybeRwSignal<bool>>,
|
||||
) -> UseToggleReturn<impl Fn() + Clone + 'static> {
|
||||
let initial_value = initial_value.into();
|
||||
let (value, set_value) = initial_value.into_signal();
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ async fn create_media(video: bool, audio: bool) -> Result<web_sys::MediaStream,
|
|||
}
|
||||
|
||||
/// Options for [`use_user_media_with_options`].
|
||||
///
|
||||
/// Either or both constraints must be specified.
|
||||
/// If the browser cannot find all media tracks with the specified types that meet the constraints given,
|
||||
/// then the returned promise is rejected with `NotFoundError`
|
||||
|
|
|
@ -359,6 +359,7 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
|
|||
}
|
||||
|
||||
/// Options for [`UseWebNotificationReturn::show`].
|
||||
///
|
||||
/// This can be used to override options passed to [`use_web_notification`].
|
||||
/// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info.
|
||||
///
|
||||
|
|
Loading…
Add table
Reference in a new issue