use dioxus::core::{ElementId, Mutation::*}; use dioxus::prelude::*; #[test] fn state_shares() { fn app(cx: Scope) -> Element { cx.provide_context(generation() as i32); render!(child_1 {}) } fn child_1(cx: Scope) -> Element { render!(child_2 {}) } fn child_2(cx: Scope) -> Element { let value = cx.consume_context::().unwrap(); render!("Value is {value}") } let mut dom = VirtualDom::new(app); assert_eq!( dom.rebuild_to_vec().santize().edits, [ CreateTextNode { value: "Value is 0".to_string(), id: ElementId(1,) }, AppendChildren { m: 1, id: ElementId(0) }, ] ); dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate_to_vec(); assert_eq!(dom.base_scope().consume_context::().unwrap(), 1); dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate_to_vec(); assert_eq!(dom.base_scope().consume_context::().unwrap(), 2); dom.mark_dirty(ScopeId(2)); assert_eq!( dom.render_immediate_to_vec().santize().edits, [SetText { value: "Value is 2".to_string(), id: ElementId(1,) },] ); dom.mark_dirty(ScopeId::ROOT); dom.mark_dirty(ScopeId(2)); let edits = dom.render_immediate_to_vec(); assert_eq!( edits.santize().edits, [SetText { value: "Value is 3".to_string(), id: ElementId(1,) },] ); }