extern crate messenger; extern crate serde_json; extern crate tokio; #[macro_use] extern crate virtual_view; use std::sync::{Arc, Mutex}; use std::sync::atomic::{AtomicUsize, Ordering}; use serde_json::from_value; use tokio::executor::current_thread; use virtual_view::{Children, Component, EventManager, Instance, Props, Renderer, Transaction, View}; struct Comp0; impl Component for Comp0 { fn name(&self) -> &'static str { "Comp0" } fn inherit_context(&self, mut context: Props, parent_context: &Props) -> Props { context.extend(parent_context); context } fn render(&self, instance: &Instance, _: &Props, _: &Children) -> View { let color = instance.context.take("color").unwrap(); view! {
{0}
} } } struct Comp1; impl Component for Comp1 { fn name(&self) -> &'static str { "Comp1" } fn inherit_context(&self, mut context: Props, parent_context: &Props) -> Props { context.extend(parent_context); context } fn render(&self, instance: &Instance, _: &Props, _: &Children) -> View { let color = instance.context.take("color").unwrap(); view! {{1}
} } } struct TopComp; impl Component for TopComp { fn name(&self) -> &'static str { "TopComp" } fn initial_state(&self, _: &Props) -> Props { props! { "render": true, } } fn context(&self, _: &Props) -> Props { props! { "color": "#F00", } } fn will_mount(&self, instance: &Instance) { instance.set_state(|current| { let render = current.get("render").boolean().unwrap(); let mut next = current.clone(); next.insert("render", !render); next }); } fn render(&self, instance: &Instance, _: &Props, _: &Children) -> View { view! {