Skip to content

Commit

Permalink
Address reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed May 23, 2022
1 parent 5784ec7 commit 7e12d61
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 6 deletions.
30 changes: 30 additions & 0 deletions packages/yew-macro/tests/hook_macro/use_prepared_state-fail.rs
@@ -0,0 +1,30 @@
use yew::prelude::*;
use yew_macro::{use_prepared_state_with_closure, use_prepared_state_without_closure};

#[function_component]
fn Comp() -> HtmlResult {
use_prepared_state_with_closure!(123)?;

use_prepared_state_with_closure!(|_| { todo!() }, 123)?;

use_prepared_state_with_closure!(|_| -> u32 { todo!() })?;

use_prepared_state_with_closure!(async |_| -> u32 { todo!() })?;

Ok(Html::default())
}

#[function_component]
fn Comp2() -> HtmlResult {
use_prepared_state_without_closure!(123)?;

use_prepared_state_without_closure!(|_| { todo!() }, 123)?;

use_prepared_state_without_closure!(|_| -> u32 { todo!() })?;

use_prepared_state_without_closure!(async |_| -> u32 { todo!() })?;

Ok(Html::default())
}

fn main() {}
55 changes: 55 additions & 0 deletions packages/yew-macro/tests/hook_macro/use_prepared_state-fail.stderr
@@ -0,0 +1,55 @@
error: expected `|`
--> tests/hook_macro/use_prepared_state-fail.rs:6:38
|
6 | use_prepared_state_with_closure!(123)?;
| ^^^

error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle.
--> tests/hook_macro/use_prepared_state-fail.rs:8:38
|
8 | use_prepared_state_with_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
--> tests/hook_macro/use_prepared_state-fail.rs:10:5
|
10 | use_prepared_state_with_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `,`
--> tests/hook_macro/use_prepared_state-fail.rs:12:5
|
12 | use_prepared_state_with_closure!(async |_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `|`
--> tests/hook_macro/use_prepared_state-fail.rs:19:41
|
19 | use_prepared_state_without_closure!(123)?;
| ^^^

error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle.
--> tests/hook_macro/use_prepared_state-fail.rs:21:41
|
21 | use_prepared_state_without_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
--> tests/hook_macro/use_prepared_state-fail.rs:23:5
|
23 | use_prepared_state_without_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `,`
--> tests/hook_macro/use_prepared_state-fail.rs:25:5
|
25 | use_prepared_state_without_closure!(async |_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info)
26 changes: 26 additions & 0 deletions packages/yew-macro/tests/hook_macro/use_transitive_state-fail.rs
@@ -0,0 +1,26 @@
use yew::prelude::*;
use yew_macro::{use_transitive_state_with_closure, use_transitive_state_without_closure};

#[function_component]
fn Comp() -> HtmlResult {
use_transitive_state_with_closure!(123)?;

use_transitive_state_with_closure!(|_| { todo!() }, 123)?;

use_transitive_state_with_closure!(|_| -> u32 { todo!() })?;

Ok(Html::default())
}

#[function_component]
fn Comp2() -> HtmlResult {
use_transitive_state_without_closure!(123)?;

use_transitive_state_without_closure!(|_| { todo!() }, 123)?;

use_transitive_state_without_closure!(|_| -> u32 { todo!() })?;

Ok(Html::default())
}

fn main() {}
@@ -0,0 +1,39 @@
error: expected `|`
--> tests/hook_macro/use_transitive_state-fail.rs:6:40
|
6 | use_transitive_state_with_closure!(123)?;
| ^^^

error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle.
--> tests/hook_macro/use_transitive_state-fail.rs:8:40
|
8 | use_transitive_state_with_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
--> tests/hook_macro/use_transitive_state-fail.rs:10:5
|
10 | use_transitive_state_with_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_transitive_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `|`
--> tests/hook_macro/use_transitive_state-fail.rs:17:43
|
17 | use_transitive_state_without_closure!(123)?;
| ^^^

error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle.
--> tests/hook_macro/use_transitive_state-fail.rs:19:43
|
19 | use_transitive_state_without_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
--> tests/hook_macro/use_transitive_state-fail.rs:21:5
|
21 | use_transitive_state_without_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_transitive_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info)
7 changes: 7 additions & 0 deletions packages/yew-macro/tests/hook_macro_test.rs
@@ -0,0 +1,7 @@
#[allow(dead_code)]
#[rustversion::attr(stable(1.56), test)]
fn tests() {
let t = trybuild::TestCases::new();
t.pass("tests/hook_macro/*-pass.rs");
t.compile_fail("tests/hook_macro/*-fail.rs");
}
10 changes: 6 additions & 4 deletions packages/yew/src/functional/hooks/use_prepared_state/mod.rs
Expand Up @@ -32,11 +32,12 @@ pub use feat_ssr::*;
/// It has the following signature:
///
/// ```
/// # use yew::prelude::*;
/// # use serde::de::DeserializeOwned;
/// # use serde::Serialize;
/// # use std::rc::Rc;
/// # use yew::suspense::SuspensionResult;
/// use yew::prelude::*;
/// use yew::suspense::SuspensionResult;
///
/// #[hook]
/// pub fn use_prepared_state<T, D, F>(f: F, deps: D) -> SuspensionResult<Option<Rc<T>>>
/// where
Expand All @@ -53,12 +54,13 @@ pub use feat_ssr::*;
/// When accepting an async closure, it has the following signature:
///
/// ```
/// # use yew::prelude::*;
/// # use serde::de::DeserializeOwned;
/// # use serde::Serialize;
/// # use yew::suspense::SuspensionResult;
/// # use std::rc::Rc;
/// # use std::future::Future;
/// use yew::prelude::*;
/// use yew::suspense::SuspensionResult;
///
/// #[hook]
/// pub fn use_prepared_state<T, D, F, U>(
/// f: F,
Expand Down
5 changes: 3 additions & 2 deletions packages/yew/src/functional/hooks/use_transitive_state/mod.rs
Expand Up @@ -32,11 +32,12 @@ pub use feat_ssr::*;
/// It has the following function signature:
///
/// ```
/// # use yew::prelude::*;
/// # use serde::de::DeserializeOwned;
/// # use serde::Serialize;
/// # use std::rc::Rc;
/// # use yew::suspense::SuspensionResult;
/// use yew::prelude::*;
/// use yew::suspense::SuspensionResult;
///
/// #[hook]
/// pub fn use_transitive_state<T, D, F>(f: F, deps: D) -> SuspensionResult<Option<Rc<T>>>
/// where
Expand Down

0 comments on commit 7e12d61

Please sign in to comment.