Run a closure inside a Dioxus runtime context so that Store/CopyValue APIs are available. The closure runs inside a component render.
(f: impl Fn() + 'static)
| 297 | /// Run a closure inside a Dioxus runtime context so that Store/CopyValue |
| 298 | /// APIs are available. The closure runs inside a component render. |
| 299 | fn with_runtime(f: impl Fn() + 'static) { |
| 300 | let result = Rc::new(Cell::new(false)); |
| 301 | let result2 = result.clone(); |
| 302 | let test_fn = Rc::new(f); |
| 303 | let mut dom = VirtualDom::new_with_props( |
| 304 | |props: TestHarnessProps| { |
| 305 | (props.test_fn)(); |
| 306 | props.result.set(true); |
| 307 | rsx! { div {} } |
| 308 | }, |
| 309 | TestHarnessProps { |
| 310 | test_fn, |
| 311 | result: result2, |
| 312 | }, |
| 313 | ); |
| 314 | dom.rebuild_in_place(); |
| 315 | assert!(result.get(), "Test component did not run"); |
| 316 | } |
| 317 | |
| 318 | #[derive(Clone, Props)] |
| 319 | struct TestHarnessProps { |
no outgoing calls