Minor refactoring
Changed the "Msg" type of "Wrapper" from "String" to "WrapperMsg".
This commit is contained in:
parent
3ffeb45de4
commit
2fb5a18636
1 changed files with 10 additions and 7 deletions
|
@ -42,7 +42,7 @@ impl Component for Slot {
|
||||||
match msg {
|
match msg {
|
||||||
SlotMessage::Press(idx) => {
|
SlotMessage::Press(idx) => {
|
||||||
// notify Wrapper with message
|
// notify Wrapper with message
|
||||||
let msg = format!("pressed {idx}");
|
let msg = WrapperMsg::Pressed(idx);
|
||||||
if let Some(p) = ctx.link().get_parent() {
|
if let Some(p) = ctx.link().get_parent() {
|
||||||
p.clone().downcast::<Wrapper>().send_message(msg);
|
p.clone().downcast::<Wrapper>().send_message(msg);
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,12 @@ impl Component for Slot {
|
||||||
|
|
||||||
pub struct Wrapper {}
|
pub struct Wrapper {}
|
||||||
|
|
||||||
|
pub enum WrapperMsg {
|
||||||
|
Pressed(u8),
|
||||||
|
}
|
||||||
|
|
||||||
impl Component for Wrapper {
|
impl Component for Wrapper {
|
||||||
type Message = String;
|
type Message = WrapperMsg;
|
||||||
type Properties = ();
|
type Properties = ();
|
||||||
|
|
||||||
fn create(_ctx: &Context<Self>) -> Self {
|
fn create(_ctx: &Context<Self>) -> Self {
|
||||||
|
@ -144,9 +148,8 @@ impl Component for Wrapper {
|
||||||
let window = web_sys::window().expect("no window exists");
|
let window = web_sys::window().expect("no window exists");
|
||||||
let document = window.document().expect("window should have a document");
|
let document = window.document().expect("window should have a document");
|
||||||
|
|
||||||
let split_str: Vec<&str> = msg.split_whitespace().collect();
|
match msg {
|
||||||
if split_str.len() == 2 && split_str[0] == "pressed" {
|
WrapperMsg::Pressed(idx) => {
|
||||||
if let Ok(idx) = split_str[1].parse::<u8>() {
|
|
||||||
let mut bottom_idx = idx;
|
let mut bottom_idx = idx;
|
||||||
let mut placed = false;
|
let mut placed = false;
|
||||||
let current_player = shared.turn.get();
|
let current_player = shared.turn.get();
|
||||||
|
@ -277,8 +280,8 @@ impl Component for Wrapper {
|
||||||
} else {
|
} else {
|
||||||
log::warn!("Failed to get side \"info_text\"");
|
log::warn!("Failed to get side \"info_text\"");
|
||||||
}
|
}
|
||||||
} // let Ok(idx) = split_str[1].parse::<u8>()
|
} // WrapperMsg::Pressed(idx) =>
|
||||||
} // split_str.len() == 2 && split_str[0] == "pressed"
|
} // match (msg)
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue