Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to yew master branch #14

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/yew-hooks-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ documentation = "https://github.com/jetli/yew-hooks"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yew = "0.19.3"
yew = { git = "https://github.com/yewstack/yew", features=["csr"]}
4 changes: 2 additions & 2 deletions crates/yew-hooks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ documentation = "https://docs.rs/yew-hooks/"

[dependencies]
log = "0.4"
yew = "0.19.3"
gloo = "0.4"
yew = { git = "https://github.com/yewstack/yew", features=["csr"] }
gloo = "0.7"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
serde = "1"
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ where
/// Ok(String::from("Jet Li"))
/// }
/// ```
#[hook]
pub fn use_async<F, T, E>(future: F) -> UseAsyncHandle<T, E>
where
F: Future<Output = Result<T, E>> + 'static,
Expand Down Expand Up @@ -188,6 +189,7 @@ where
/// Ok(String::from("Jet Li"))
/// }
/// ```
#[hook]
pub fn use_async_with_options<F, T, E>(future: F, options: UseAsyncOptions) -> UseAsyncHandle<T, E>
where
F: Future<Output = Result<T, E>> + 'static,
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_before_unload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use web_sys::BeforeUnloadEvent;
use yew::prelude::*;

use super::use_event_with_window;

Expand All @@ -21,6 +22,7 @@ use super::use_event_with_window;
/// }
/// }
/// ```
#[hook]
pub fn use_before_unload(enabled: bool, msg: String) {
use_event_with_window("beforeunload", move |e: BeforeUnloadEvent| {
if !enabled {
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_click_away.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use super::{use_event_with_window, use_latest};
/// }
/// }
/// ```
#[hook]
pub fn use_click_away<F>(node: NodeRef, callback: F)
where
F: Fn(Event) + 'static,
Expand Down
33 changes: 20 additions & 13 deletions crates/yew-hooks/src/hooks/use_clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,32 @@ impl Clone for UseClipboardHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_clipboard() -> UseClipboardHandle {
let text = use_state_ptr_eq(|| None);
let bytes = use_state_ptr_eq(|| None);
let bytes_mime_type = use_state_ptr_eq(|| None);
let is_supported = use_ref(|| {
window()
.expect_throw("Can't find the global Window")
.navigator()
.clipboard()
.is_some()
});
let is_supported = use_memo(
|_| {
window()
.expect_throw("Can't find the global Window")
.navigator()
.clipboard()
.is_some()
},
(),
);
let copied = use_state_ptr_eq(|| false);

let clipboard = use_ref(|| {
window()
.expect_throw("Can't find the global Window")
.navigator()
.clipboard()
});
let clipboard = use_memo(
|_| {
window()
.expect_throw("Can't find the global Window")
.navigator()
.clipboard()
},
(),
);

let write_text = {
let clipboard = clipboard.clone();
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl PartialEq for UseCounterHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_counter(default: i32) -> UseCounterHandle {
let inner = use_reducer(move || UseCounterReducer {
value: default,
Expand Down
3 changes: 3 additions & 0 deletions crates/yew-hooks/src/hooks/use_debounce.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use yew::prelude::*;

use super::{use_timeout, UseTimeoutHandle};

/// State handle for the [`use_debounce`] hook.
Expand Down Expand Up @@ -84,6 +86,7 @@ impl Clone for UseDebounceHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_debounce<Callback>(callback: Callback, millis: u32) -> UseDebounceHandle
where
Callback: FnOnce() + 'static,
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_debounce_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use super::{use_debounce, use_unmount};
/// }
/// }
/// ```
#[hook]
pub fn use_debounce_effect<Callback>(callback: Callback, millis: u32)
where
Callback: FnOnce() + 'static,
Expand All @@ -82,6 +83,7 @@ where
///
/// Whenever the dependencies are changed, the debounce effect is run again.
/// To detect changes, dependencies must implement `PartialEq`.
#[hook]
pub fn use_debounce_effect_with_deps<Callback, Dependents>(
callback: Callback,
millis: u32,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_debounce_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_debounce_state<T, F>(init_fn: F, millis: u32) -> UseDebounceStateHandle<T>
where
T: 'static,
Expand Down
3 changes: 2 additions & 1 deletion crates/yew-hooks/src/hooks/use_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_default<T, F>(init_fn: F, default: T) -> UseDefaultHandle<T>
where
T: 'static,
F: FnOnce() -> Option<T>,
{
let inner = use_state(init_fn);
let default = use_ref(|| default);
let default = use_memo(|_| default, ());

UseDefaultHandle { inner, default }
}
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct UseDragHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_drag(node: NodeRef) -> UseDragHandle {
use_drag_with_options(node, UseDragOptions::default())
}
Expand Down Expand Up @@ -85,6 +86,7 @@ pub fn use_drag(node: NodeRef) -> UseDragHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_drag_with_options(node: NodeRef, options: UseDragOptions) -> UseDragHandle {
let dragging = use_state(|| false);

Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct UseDropHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_drop(node: NodeRef) -> UseDropHandle {
use_drop_with_options(node, UseDropOptions::default())
}
Expand Down Expand Up @@ -119,6 +120,7 @@ pub fn use_drop(node: NodeRef) -> UseDropHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_drop_with_options(node: NodeRef, options: UseDropOptions) -> UseDropHandle {
let over = use_state(|| false);
let files = use_state(|| None);
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_effect_once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use yew::prelude::*;
/// }
/// }
/// ```
#[hook]
pub fn use_effect_once<Callback, Destructor>(callback: Callback)
where
Callback: FnOnce() -> Destructor + 'static,
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_effect_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use super::use_is_first_mount;
/// }
/// }
/// ```
#[hook]
pub fn use_effect_update<Callback, Destructor>(callback: Callback)
where
Callback: FnOnce() -> Destructor + 'static,
Expand All @@ -45,6 +46,7 @@ where

/// This hook is similar to [`use_effect_update`] but it accepts dependencies.
/// The signature is exactly the same as the [`use_effect_with_deps`] hook.
#[hook]
pub fn use_effect_update_with_deps<Callback, Destructor, Dependents>(
callback: Callback,
deps: Dependents,
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use super::use_latest;
/// }
/// }
/// ```
#[hook]
pub fn use_event<T, F, E>(node: NodeRef, event_type: T, callback: F)
where
T: Into<Cow<'static, str>>,
Expand Down Expand Up @@ -102,6 +103,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_event_with_window<T, F, E>(event_type: T, callback: F)
where
T: Into<Cow<'static, str>>,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_favicon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use yew::prelude::*;
/// }
/// }
/// ```
#[hook]
pub fn use_favicon(href: String) {
use_effect_with_deps(
move |href| {
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_geolocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ pub struct UseGeolocationState {
/// }
/// }
/// ```
#[hook]
pub fn use_geolocation() -> UseGeolocationState {
use_geolocation_with_options(UseGeolocationOptions::default())
}

/// A sensor hook that tracks user's geographic location.
/// See [`use_geolocation`]
#[hook]
pub fn use_geolocation_with_options(options: UseGeolocationOptions) -> UseGeolocationState {
let state = use_state(|| UseGeolocationState {
loading: true,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl PartialEq for UseHashHandle {
/// }
/// }
/// ```
#[hook]
pub fn use_hash() -> UseHashHandle {
let inner = use_state(|| window().location().hash().unwrap_or_default());

Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_infinite_scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use super::{use_debounce, use_event, use_latest};
/// }
/// }
/// ```
#[hook]
pub fn use_infinite_scroll<Callback>(node: NodeRef, callback: Callback)
where
Callback: Fn() + 'static,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use super::use_mut_latest;
/// }
/// }
/// ```
#[hook]
pub fn use_interval<Callback>(callback: Callback, millis: u32)
where
Callback: FnMut() + 'static,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_is_first_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use yew::prelude::*;
/// }
/// }
/// ```
#[hook]
pub fn use_is_first_mount() -> bool {
let is_first = use_mut_ref(|| true);

Expand Down
3 changes: 2 additions & 1 deletion crates/yew-hooks/src/hooks/use_is_mounted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use super::use_effect_once;
/// }
/// }
/// ```
pub fn use_is_mounted() -> Rc<impl Fn() -> bool> {
#[hook]
pub fn use_is_mounted() -> Rc<dyn Fn() -> bool> {
let is_mounted = use_mut_ref(|| false);

{
Expand Down
2 changes: 2 additions & 0 deletions crates/yew-hooks/src/hooks/use_latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_mut_latest<T>(value: T) -> UseMutLatestHandle<T>
where
T: 'static,
Expand Down Expand Up @@ -153,6 +154,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_latest<T>(value: T) -> UseLatestHandle<T>
where
T: 'static,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_list<T>(initial_value: Vec<T>) -> UseListHandle<T>
where
T: 'static,
Expand Down
3 changes: 2 additions & 1 deletion crates/yew-hooks/src/hooks/use_local_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_local_storage<T>(key: String) -> UseLocalStorageHandle<T>
where
T: for<'de> Deserialize<'de> + 'static,
{
let inner: UseStateHandle<Option<T>> =
use_state(|| LocalStorage::get(&key).unwrap_or_default());
let key = use_ref(|| key);
let key = use_memo(|_| key, ());

{
let key = key.clone();
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct LocationState {
/// }
/// }
/// ```
#[hook]
pub fn use_location() -> UseStateHandle<LocationState> {
let state = use_state(|| build_location("load".to_string()));

Expand Down
4 changes: 4 additions & 0 deletions crates/yew-hooks/src/hooks/use_logger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fmt::Debug;
use std::rc::Rc;

use yew::prelude::*;

use super::{use_effect_once, use_effect_update, use_effect_update_with_deps, use_previous};

/// This hook logs in console as component goes through life-cycles.
Expand Down Expand Up @@ -36,6 +38,7 @@ use super::{use_effect_once, use_effect_update, use_effect_update_with_deps, use
/// pub b: String,
/// }
/// ```
#[hook]
pub fn use_logger<T>(name: String, props: T)
where
T: Debug + 'static,
Expand Down Expand Up @@ -95,6 +98,7 @@ where
/// pub b: String,
/// }
/// ```
#[hook]
pub fn use_logger_eq<T>(name: String, props: T)
where
T: Debug + PartialEq + 'static,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ where
/// }
/// }
/// ```
#[hook]
pub fn use_map<K, V>(initial_value: HashMap<K, V>) -> UseMapHandle<K, V>
where
K: 'static,
Expand Down
1 change: 1 addition & 0 deletions crates/yew-hooks/src/hooks/use_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct UseMeasureState {
/// }
/// }
/// ```
#[hook]
pub fn use_measure(node: NodeRef) -> UseMeasureState {
let state = use_raf_state(UseMeasureState::default);

Expand Down
Loading