view render method
*/
// imports
-use super::{Component, InputEvent, Msg, Payload, Props, PropsBuilder};
+use super::{Component, InputEvent, Msg, Payload, Props, PropsBuilder, Render};
// ext
use std::collections::HashMap;
@@ -69,6 +69,18 @@ impl View {
self.components.remove(id);
}
+ // -- render
+
+ /// ### render
+ ///
+ /// Render component with the provided id
+ pub fn render(&self, id: &str) -> Option<Render> {
+ match self.components.get(id) {
+ None => None,
+ Some(component) => component.render(),
+ }
+ }
+
// -- props
/// ### get_props
@@ -224,6 +236,16 @@ mod tests {
assert!(view.components.get(text).is_none());
}
+ #[test]
+ fn test_ui_layout_view_mount_render() {
+ let mut view: View = View::init();
+ // Mount component
+ let input: &str = "INPUT";
+ view.mount(input, make_component_input());
+ assert!(view.render(input).is_some());
+ assert!(view.render("unexisting").is_none());
+ }
+
#[test]
fn test_ui_layout_view_focus() {
let mut view: View = View::init();
@@ -352,7 +374,10 @@ mod tests {
assert_eq!(
view.on(InputEvent::Key(KeyEvent::from(KeyCode::Enter)))
.unwrap(),
- (input.to_string(), Msg::OnSubmit(Payload::Text(String::from("text1"))))
+ (
+ input.to_string(),
+ Msg::OnSubmit(Payload::Text(String::from("text1")))
+ )
);
}
