mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-02-02 10:54:15 -05:00
added is_none and is_some
This commit is contained in:
parent
6897c3d1f1
commit
67bdde2960
10 changed files with 90 additions and 0 deletions
|
@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### New Functions 🚀
|
### New Functions 🚀
|
||||||
|
|
||||||
|
- `is_none`
|
||||||
|
- `is_some`
|
||||||
- `use_raf_fn`
|
- `use_raf_fn`
|
||||||
|
|
||||||
### Braking Changes 🛠
|
### Braking Changes 🛠
|
||||||
|
|
|
@ -63,6 +63,8 @@
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
|
|
||||||
|
- [is_none](utilities/is_none.md)
|
||||||
|
- [is_some](utilities/is_some.md)
|
||||||
- [use_cycle_list](utilities/use_cycle_list.md)
|
- [use_cycle_list](utilities/use_cycle_list.md)
|
||||||
- [use_debounce_fn](utilities/use_debounce_fn.md)
|
- [use_debounce_fn](utilities/use_debounce_fn.md)
|
||||||
- [use_supported](utilities/use_supported.md)
|
- [use_supported](utilities/use_supported.md)
|
||||||
|
|
3
docs/book/src/utilities/is_none.md
Normal file
3
docs/book/src/utilities/is_none.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# is_none
|
||||||
|
|
||||||
|
<!-- cmdrun python3 ../extract_doc_comment.py is_none -->
|
3
docs/book/src/utilities/is_some.md
Normal file
3
docs/book/src/utilities/is_some.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# is_some
|
||||||
|
|
||||||
|
<!-- cmdrun python3 ../extract_doc_comment.py is_some -->
|
|
@ -2,6 +2,8 @@
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
|
"is_none",
|
||||||
|
"is_some",
|
||||||
"on_click_outside",
|
"on_click_outside",
|
||||||
"use_abs",
|
"use_abs",
|
||||||
"use_active_element",
|
"use_active_element",
|
||||||
|
|
27
src/is_none.rs
Normal file
27
src/is_none.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use crate::utils::use_derive_signal;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
use_derive_signal!(
|
||||||
|
/// Reactive `Option::is_none()`.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use leptos::*;
|
||||||
|
/// # use leptos_use::is_none;
|
||||||
|
/// #
|
||||||
|
/// # #[component]
|
||||||
|
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||||
|
/// let (example, set_example) = create_signal(
|
||||||
|
/// cx,
|
||||||
|
/// if js_sys::Math::random() < 0.5 { Some("Example") } else { None }
|
||||||
|
/// );
|
||||||
|
///
|
||||||
|
/// let is_empty = is_none(cx, example);
|
||||||
|
/// #
|
||||||
|
/// # view! { cx, }
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
is_none<Option<T>, T: 'static> -> bool
|
||||||
|
|value| value.is_none()
|
||||||
|
);
|
27
src/is_some.rs
Normal file
27
src/is_some.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use crate::utils::use_derive_signal;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
use_derive_signal!(
|
||||||
|
/// Reactive `Option::is_some()`.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use leptos::*;
|
||||||
|
/// # use leptos_use::is_some;
|
||||||
|
/// #
|
||||||
|
/// # #[component]
|
||||||
|
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||||
|
/// let (example, set_example) = create_signal(
|
||||||
|
/// cx,
|
||||||
|
/// if js_sys::Math::random() < 0.5 { Some("Example") } else { None }
|
||||||
|
/// );
|
||||||
|
///
|
||||||
|
/// let not_empty = is_some(cx, example);
|
||||||
|
/// #
|
||||||
|
/// # view! { cx, }
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
is_some<Option<T>, T: 'static> -> bool
|
||||||
|
|value| value.is_some()
|
||||||
|
);
|
|
@ -21,6 +21,8 @@ cfg_if! { if #[cfg(web_sys_unstable_apis)] {
|
||||||
}}
|
}}
|
||||||
|
|
||||||
mod on_click_outside;
|
mod on_click_outside;
|
||||||
|
mod is_none;
|
||||||
|
mod is_some;
|
||||||
mod use_active_element;
|
mod use_active_element;
|
||||||
mod use_breakpoints;
|
mod use_breakpoints;
|
||||||
mod use_color_mode;
|
mod use_color_mode;
|
||||||
|
@ -56,6 +58,8 @@ mod watch_throttled;
|
||||||
mod whenever;
|
mod whenever;
|
||||||
|
|
||||||
pub use on_click_outside::*;
|
pub use on_click_outside::*;
|
||||||
|
pub use is_none::*;
|
||||||
|
pub use is_some::*;
|
||||||
pub use use_active_element::*;
|
pub use use_active_element::*;
|
||||||
pub use use_breakpoints::*;
|
pub use use_breakpoints::*;
|
||||||
pub use use_color_mode::*;
|
pub use use_color_mode::*;
|
||||||
|
|
|
@ -3,9 +3,11 @@ mod filters;
|
||||||
mod is;
|
mod is;
|
||||||
mod js_value_from_to_string;
|
mod js_value_from_to_string;
|
||||||
mod pausable;
|
mod pausable;
|
||||||
|
mod use_derive_signal;
|
||||||
|
|
||||||
pub use clonable_fn::*;
|
pub use clonable_fn::*;
|
||||||
pub use filters::*;
|
pub use filters::*;
|
||||||
pub use is::*;
|
pub use is::*;
|
||||||
pub(crate) use js_value_from_to_string::*;
|
pub(crate) use js_value_from_to_string::*;
|
||||||
pub use pausable::*;
|
pub use pausable::*;
|
||||||
|
pub(crate) use use_derive_signal::*;
|
||||||
|
|
18
src/utils/use_derive_signal.rs
Normal file
18
src/utils/use_derive_signal.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
macro_rules! use_derive_signal {
|
||||||
|
(
|
||||||
|
$(#[$outer:meta])*
|
||||||
|
$name:ident <$inner_signal_type:tt $(< $( $inner_type_param:tt ),+ >)? $(, $( $type_param:tt $( : $first_bound:tt $(+ $rest_bound:tt)* )? ),+ )? > -> $return_type:tt
|
||||||
|
$($body:tt)+
|
||||||
|
) => {
|
||||||
|
$(#[$outer])*
|
||||||
|
pub fn $name<V $(, $( $type_param ),* )? >(cx: Scope, value: V) -> Signal<$return_type>
|
||||||
|
where
|
||||||
|
V: Into<MaybeSignal<$inner_signal_type $(< $( $inner_type_param ),+ >)?>> $(, $( $type_param $( : $first_bound $(+ $rest_bound)* )? ),+ )?
|
||||||
|
{
|
||||||
|
let value = value.into();
|
||||||
|
Signal::derive(cx, move || value.with($($body)+))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) use use_derive_signal;
|
Loading…
Add table
Reference in a new issue