use crate::{nodebuilder::IntoDomTree, prelude::*};
use crate::{nodebuilder::LazyNodes, nodes::VNode};
use bumpalo::Bump;
use hooks::Hook;
use std::{cell::RefCell, future::Future, ops::Deref, pin::Pin, rc::Rc, sync::atomic::AtomicUsize};
/// Components in Dioxus use the "Context" object to interact with their lifecycle.
/// This lets components schedule updates, integrate hooks, and expose their context via the context api.
///
/// Properties passed down from the parent component are also directly accessible via the exposed "props" field.
///
/// ```ignore
/// #[derive(Properties)]
/// struct Props {
/// name: String
///
/// }
///
/// fn example(ctx: Context, props: &Props -> VNode {
/// html! {
///
"Hello, {ctx.props.name}"
/// }
/// }
/// ```
// todo: force lifetime of source into T as a valid lifetime too
// it's definitely possible, just needs some more messing around
pub struct Context<'src> {
pub idx: RefCell,
pub scope: ScopeIdx,
// Borrowed from scope
// pub(crate) arena: &'src typed_arena::Arena,
pub(crate) hooks: &'src RefCell>,
// pub(crate) hooks: &'src RefCell>,
pub(crate) bump: &'src Bump,
pub listeners: &'src RefCell>,
// holder for the src lifetime
// todo @jon remove this
pub _p: std::marker::PhantomData<&'src ()>,
}
impl<'a> Context<'a> {
/// Access the children elements passed into the component
pub fn children(&self) -> Vec {
todo!("Children API not yet implemented for component Context")
}
pub fn callback(&self, _f: impl Fn(()) + 'a) {}
// call this closure after the component has been committed to the editlist
// this provides the founation of "use_effect"
fn post_update() {}
/// Create a subscription that schedules a future render for the reference component
pub fn schedule_update(&self) -> impl Fn() -> () {
|| {}
}
/// Create a suspended component from a future.
///
/// When the future completes, the component will be renderered
pub fn suspend FnOnce(&'b NodeCtx<'a>) -> VNode<'a> + 'a>(
&self,
_fut: impl Future