Feat: add some docs

This commit is contained in:
Jonathan Kelley committed 2021-03-10 19:24:45 -05:00
1 parent ddaa55a04a
commit 5abda91892
2 files changed
+8 -9

No files matched your search

+1
View File
@@ -6,6 +6,7 @@
//! that ensures compile-time required and optional fields on props. //! that ensures compile-time required and optional fields on props.
use crate::innerlude::FC; use crate::innerlude::FC;
pub type ScopeIdx = generational_arena::Index; pub type ScopeIdx = generational_arena::Index;
pub trait Properties: PartialEq { pub trait Properties: PartialEq {
+7 -9
View File
@@ -2,10 +2,7 @@ use crate::nodes::VNode;
use crate::prelude::*; use crate::prelude::*;
use bumpalo::Bump; use bumpalo::Bump;
use hooks::Hook; use hooks::Hook;
use std::{ use std::{cell::RefCell, future::Future, ops::Deref, rc::Rc, sync::atomic::AtomicUsize};
any::TypeId, borrow::Borrow, cell::RefCell, future::Future, marker::PhantomData, ops::Deref,
rc::Rc, sync::atomic::AtomicUsize,
};
/// Components in Dioxus use the "Context" object to interact with their lifecycle. /// 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. /// This lets components schedule updates, integrate hooks, and expose their context via the context api.
@@ -19,7 +16,7 @@ use std::{
/// ///
/// } /// }
/// ///
/// fn example(ctx: &Context<Props>) -> VNode { /// fn example(ctx: Context, props: &Props -> VNode {
/// html! { /// html! {
/// <div> "Hello, {ctx.props.name}" </div> /// <div> "Hello, {ctx.props.name}" </div>
/// } /// }
@@ -47,7 +44,6 @@ pub struct Context<'src> {
} }
impl<'a> Context<'a> { impl<'a> Context<'a> {
// impl<'a, PropType> Context<'a, PropType> {
/// Access the children elements passed into the component /// Access the children elements passed into the component
pub fn children(&self) -> Vec<VNode> { pub fn children(&self) -> Vec<VNode> {
todo!("Children API not yet implemented for component Context") todo!("Children API not yet implemented for component Context")
@@ -55,10 +51,12 @@ impl<'a> Context<'a> {
pub fn callback(&self, _f: impl Fn(()) + 'a) {} 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 /// Create a subscription that schedules a future render for the reference component
pub fn schedule_update(&self) -> impl Fn() -> () { pub fn schedule_update(&self) -> impl Fn() -> () {
// log::debug!()
// todo!("Subscription API is not ready yet");
|| {} || {}
} }
@@ -93,7 +91,7 @@ impl<'a> Context<'a> {
/// ```ignore /// ```ignore
/// fn Component(ctx: Context<Props>) -> VNode { /// fn Component(ctx: Context<Props>) -> VNode {
/// // Lazy assemble the VNode tree /// // Lazy assemble the VNode tree
/// let lazy_tree = html! {<div>"Hello World"</div>}; /// let lazy_tree = html! {<div> "Hello World" </div>};
/// ///
/// // Actually build the tree and allocate it /// // Actually build the tree and allocate it
/// ctx.render(lazy_tree) /// ctx.render(lazy_tree)