example of function memory game#2255
Conversation
|
@leftstick We really appreciate your PR, and I personally love the look of the example. But you could add a new page in the yew docs for community examples/links. Then add a link to your example repository there! |
|
I think this example is significantly more interesting than the function_todomvc example. I'd much rather incorporate this example and put a few struct to function component comparisons in the documentation. |
|
@voidpumpkin @siku2 thanks for your suggestion. Since it is the first time I tried rust, the implementation might not elegant enough. Let me know if you have any further comments. |
| #[derive(Properties, Clone)] | ||
| pub struct Props { | ||
| pub cards: Vec<Card>, | ||
| pub on_flip: Callback<RawCard>, | ||
| } | ||
|
|
||
| impl PartialEq for Props { | ||
| fn eq(&self, other: &Props) -> bool { | ||
| let s_cards = &self.cards; | ||
| let o_cards = &other.cards; | ||
| let s_cards_len = s_cards.len(); | ||
| let o_cards_len = o_cards.len(); | ||
|
|
||
| match s_cards_len == o_cards_len { | ||
| false => false, | ||
| true => s_cards.iter().all(|c| o_cards.contains(c)), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I'm a little confused why not derive PartialEq automatically?
| #[derive(Properties, Clone)] | |
| pub struct Props { | |
| pub cards: Vec<Card>, | |
| pub on_flip: Callback<RawCard>, | |
| } | |
| impl PartialEq for Props { | |
| fn eq(&self, other: &Props) -> bool { | |
| let s_cards = &self.cards; | |
| let o_cards = &other.cards; | |
| let s_cards_len = s_cards.len(); | |
| let o_cards_len = o_cards.len(); | |
| match s_cards_len == o_cards_len { | |
| false => false, | |
| true => s_cards.iter().all(|c| o_cards.contains(c)), | |
| } | |
| } | |
| } | |
| #[derive(Properties, Clone, PartialEq)] | |
| pub struct Props { | |
| pub cards: Vec<Card>, | |
| pub on_flip: Callback<RawCard>, | |
| } | |
There was a problem hiding this comment.
@voidpumpkin Thanks for your suggestion. I misunderstood the automatic PartialEq before. I tried replace with automatic implementation, it's working properly.
I've committed the change
ranile
left a comment
There was a problem hiding this comment.
Might also want to use the new syntax for function component macro (one where function name is the component name). It's also fine as is
| ## LICENSE | ||
|
|
||
| [MIT License](https://raw.githubusercontent.com/yewstack/yew/examples/function_memory_game/master/LICENSE) |
There was a problem hiding this comment.
Why is the license specified here? Why is it only MIT? The example's Cargo.toml says the license is MIT to Apache 2.0.
There was a problem hiding this comment.
@hamza1311 this example should not have a specific license. I will remove this part
|
@leftstick also take a look at comments in #2313 I had a copy of your PR before you fixed yours so @siku2 reviewed that one |
|
@voidpumpkin code changed. Thanks for reviewing |
|
Please rebase onto master for tests to be fixed |
@voidpumpkin done. Thanks for reminding |
ranile
left a comment
There was a problem hiding this comment.
Just formatting and warnings. Otherwise, looks good
|
|
||
| match props.status { | ||
| Status::Ready => html! { | ||
| <span >{"Ready"}</span> |
There was a problem hiding this comment.
| <span >{"Ready"}</span> | |
| <span>{"Ready"}</span> |
There was a problem hiding this comment.
@hamza1311 Would you please share how you got such error? I ran with cargo make lint, there is no any warning. Thanks
There was a problem hiding this comment.
This is not a warning, just a formatting issue. The warnings are in other comment where @voidpumpkin explained how to run the lints
| <span >{"Ready"}</span> | ||
| }, | ||
| Status::Playing => html! { | ||
| <span >{"Playing"}</span> |
There was a problem hiding this comment.
| <span >{"Playing"}</span> | |
| <span>{"Playing"}</span> |
| html! { | ||
| <div class="chess-board-card-container"> | ||
| <div class={classes!("card", flipped.then(|| "flipped"))} {onclick}> | ||
| <img class="front" src={get_link_by_cardname} /> |
There was a problem hiding this comment.
@hamza1311 would you please share how you got those warnings? I got everything alright with cargo make lint. Thanks
There was a problem hiding this comment.
@leftstick Those are yew custom warnings that work with only nightly compiler
https://yew.rs/docs/concepts/html/introduction#lints
|
@voidpumpkin @hamza1311 done. Thanks for reviewing |
Description
Example of function memory game.
It is a different case to demonstrate how functional components work.
check below demo:
Checklist
cargo make pr-flow