mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-22 16:49:22 -05:00
added is_ok and is_err
This commit is contained in:
parent
67bdde2960
commit
880eca30da
8 changed files with 70 additions and 0 deletions
|
@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### New Functions 🚀
|
||||
|
||||
- `is_err`
|
||||
- `is_ok`
|
||||
- `is_none`
|
||||
- `is_some`
|
||||
- `use_raf_fn`
|
||||
|
|
|
@ -63,7 +63,9 @@
|
|||
|
||||
# Utilities
|
||||
|
||||
- [is_err](utilities/is_err.md)
|
||||
- [is_none](utilities/is_none.md)
|
||||
- [is_ok](utilities/is_ok.md)
|
||||
- [is_some](utilities/is_some.md)
|
||||
- [use_cycle_list](utilities/use_cycle_list.md)
|
||||
- [use_debounce_fn](utilities/use_debounce_fn.md)
|
||||
|
|
3
docs/book/src/utilities/is_err.md
Normal file
3
docs/book/src/utilities/is_err.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# is_err
|
||||
|
||||
<!-- cmdrun python3 ../extract_doc_comment.py is_err -->
|
3
docs/book/src/utilities/is_ok.md
Normal file
3
docs/book/src/utilities/is_ok.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# is_ok
|
||||
|
||||
<!-- cmdrun python3 ../extract_doc_comment.py is_ok -->
|
|
@ -2,7 +2,9 @@
|
|||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"is_err",
|
||||
"is_none",
|
||||
"is_ok",
|
||||
"is_some",
|
||||
"on_click_outside",
|
||||
"use_abs",
|
||||
|
|
27
src/is_err.rs
Normal file
27
src/is_err.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use crate::utils::use_derive_signal;
|
||||
use leptos::*;
|
||||
|
||||
use_derive_signal!(
|
||||
/// Reactive `Result::is_err()`.
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::is_err;
|
||||
/// #
|
||||
/// # #[component]
|
||||
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||
/// let (example, set_example) = create_signal(
|
||||
/// cx,
|
||||
/// if js_sys::Math::random() < 0.5 { Ok("Example") } else { Err(()) }
|
||||
/// );
|
||||
///
|
||||
/// let is_error = is_err(cx, example);
|
||||
/// #
|
||||
/// # view! { cx, }
|
||||
/// # }
|
||||
/// ```
|
||||
is_err<Result<T, ()>, T: 'static> -> bool
|
||||
|value| value.is_err()
|
||||
);
|
27
src/is_ok.rs
Normal file
27
src/is_ok.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use crate::utils::use_derive_signal;
|
||||
use leptos::*;
|
||||
|
||||
use_derive_signal!(
|
||||
/// Reactive `Result::is_ok()`.
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::is_ok;
|
||||
/// #
|
||||
/// # #[component]
|
||||
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||
/// let (example, set_example) = create_signal(
|
||||
/// cx,
|
||||
/// if js_sys::Math::random() < 0.5 { Ok("Example") } else { Err(()) }
|
||||
/// );
|
||||
///
|
||||
/// let is_ok = is_ok(cx, example);
|
||||
/// #
|
||||
/// # view! { cx, }
|
||||
/// # }
|
||||
/// ```
|
||||
is_ok<Result<T, ()>, T: 'static> -> bool
|
||||
|value| value.is_ok()
|
||||
);
|
|
@ -21,6 +21,8 @@ cfg_if! { if #[cfg(web_sys_unstable_apis)] {
|
|||
}}
|
||||
|
||||
mod on_click_outside;
|
||||
mod is_err;
|
||||
mod is_ok;
|
||||
mod is_none;
|
||||
mod is_some;
|
||||
mod use_active_element;
|
||||
|
@ -58,6 +60,8 @@ mod watch_throttled;
|
|||
mod whenever;
|
||||
|
||||
pub use on_click_outside::*;
|
||||
pub use is_err::*;
|
||||
pub use is_ok::*;
|
||||
pub use is_none::*;
|
||||
pub use is_some::*;
|
||||
pub use use_active_element::*;
|
||||
|
|
Loading…
Add table
Reference in a new issue