-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix innerText issues in diffing; tag 0.1.13
- Loading branch information
Showing
8 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! a demo for switching inner-text and children, which might cause a bug in respo | ||
|
||
use std::fmt::Debug; | ||
|
||
use respo::{button, css::RespoStyle, div, span, ui::ui_button, util, DispatchFn, RespoElement, RespoEvent}; | ||
use respo_state_derive::RespoState; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use respo::states_tree::{RespoState, RespoStatesTree}; | ||
|
||
use super::store::ActionOp; | ||
|
||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, RespoState)] | ||
struct InnerTextState { | ||
inner_text: bool, | ||
} | ||
|
||
pub fn comp_inner_text(states: &RespoStatesTree) -> Result<RespoElement<ActionOp>, String> { | ||
let cursor = states.path(); | ||
|
||
let state = states.cast_branch::<InnerTextState>(); | ||
|
||
let on_inc = { | ||
let cursor = cursor.to_owned(); | ||
let state = state.to_owned(); | ||
move |e, dispatch: DispatchFn<_>| -> Result<(), String> { | ||
util::log!("click {:?}", e); | ||
if let RespoEvent::Click { original_event, .. } = e { | ||
original_event.prevent_default(); | ||
} | ||
|
||
dispatch.run(ActionOp::Increment)?; | ||
dispatch.run_state( | ||
&cursor, | ||
InnerTextState { | ||
inner_text: !state.inner_text, | ||
}, | ||
)?; | ||
Ok(()) | ||
} | ||
}; | ||
|
||
Ok( | ||
div().elements([ | ||
div().elements([button() | ||
.class(ui_button()) | ||
.inner_text("Switch inner text") | ||
.style(RespoStyle::default().margin(4.)) | ||
.on_click(on_inc)]), | ||
div().elements([if state.inner_text { | ||
div().inner_text("inner text") | ||
} else { | ||
div().elements([span().inner_text("child 1"), span().inner_text("child 2")]) | ||
}]), | ||
]), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters