Feat: buff the readme and docs
This commit is contained in:
1 parent
b843dbd367
commit
3cfa1fe125
4 files changed
+77
-38
No files matched your search
@@ -38,7 +38,6 @@ impl Parse for RsxRender {
|
||||
Some(name)
|
||||
}
|
||||
} else {
|
||||
// todo!("NOT WORKIGN");
|
||||
None
|
||||
};
|
||||
|
||||
@@ -126,6 +125,7 @@ impl Parse for AmbiguousElement {
|
||||
.parse::<Component>()
|
||||
.map(|c| AmbiguousElement::Component(c))
|
||||
} else {
|
||||
let name = input.parse::<Ident>().unwrap();
|
||||
Err(Error::new(
|
||||
name.span(),
|
||||
"Components must be uppercased, perhaps you mispelled a html tag",
|
||||
|
||||
@@ -2,16 +2,33 @@
|
||||
// Important hooks
|
||||
// ========================
|
||||
|
||||
pub fn init_recoil_root(ctx: Context) {}
|
||||
pub fn init_recoil_root(ctx: Context) {
|
||||
let res = ctx.try_use_context::<RecoilRoot>();
|
||||
ctx.create_context(move || {
|
||||
//
|
||||
if res.is_ok() {
|
||||
panic!(
|
||||
"Cannot initialize a recoil root inside of a recoil root.\n An app may only have one recoil root per virtual dom instance"
|
||||
);
|
||||
}
|
||||
RecoilRoot {}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn use_recoil_value() {}
|
||||
pub fn use_atom<'a, T: PartialEq>(c: Context<'a>, t: &'static Atom<T>) -> &'a T {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn use_recoil() {}
|
||||
pub fn use_set_atom<'a, T: PartialEq>(c: Context<'a>, t: &'static Atom<T>) -> Rc<dyn Fn(T)> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn use_set_recoil() {}
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus_core::virtual_dom::Context;
|
||||
|
||||
pub struct RecoilRoot {}
|
||||
|
||||
pub struct RecoilContext {}
|
||||
|
||||
impl RecoilContext {
|
||||
@@ -24,7 +41,7 @@ impl RecoilContext {
|
||||
///
|
||||
/// This does not replace the value instantly.
|
||||
/// All calls to "get" will return the old value until the component is rendered.
|
||||
pub fn set<T: PartialEq, O>(&self, t: &'static Atom<T>, new: T) {
|
||||
pub fn set<T: PartialEq>(&self, t: &'static Atom<T>, new: T) {
|
||||
self.modify(t, move |old| *old = new);
|
||||
}
|
||||
|
||||
@@ -49,10 +66,6 @@ pub fn use_recoil_context<T>(c: Context) -> &T {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
pub fn use_atom<'a, T: PartialEq>(c: Context<'a>, t: &'static Atom<T>) -> &'a T {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub trait Readable {}
|
||||
impl<T: PartialEq> Readable for &'static Atom<T> {}
|
||||
impl<K: PartialEq, V: PartialEq> Readable for &'static AtomFamily<K, V> {}
|
||||
@@ -130,3 +143,34 @@ pub type Selector<O> = selector<O>;
|
||||
pub fn use_selector<'a, O>(c: Context<'a>, s: &'static Selector<O>) -> &'a O {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn callback_example(ctx: Context) {
|
||||
let set_user = use_recoil_callback(ctx, |api| {
|
||||
|a: String, b: ()| {
|
||||
//
|
||||
}
|
||||
});
|
||||
|
||||
let set_user = use_recoil_callback(ctx, |api| {
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
fn use_recoil_callback<F>(ctx: Context, f: impl Fn(RecoilContext) -> F) -> F {
|
||||
todo!()
|
||||
}
|
||||
|
||||
mod analyzer {
|
||||
use super::*;
|
||||
|
||||
const TITLE: Atom<&'static str> = atom(|_| Default::default());
|
||||
|
||||
// pub fn use_add_todo(ctx: Context) -> impl Fn(&'static str) + '_ {
|
||||
// use_recoil_callback(ctx, move |api| move |a: &'static str| api.set(&TITLE, a))
|
||||
// }
|
||||
|
||||
struct Analyzer(RecoilContext);
|
||||
fn use_analyzer(ctx: Context) -> Analyzer {
|
||||
use_recoil_callback(ctx, |api| Analyzer(api))
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
//! If you want an example on recommended project structure, check out the TodoMVC folder
|
||||
//!
|
||||
//! Here, we show to use Dioxus' Recoil state management solution to simplify app logic
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus_web::dioxus::prelude::*;
|
||||
use recoil::*;
|
||||
@@ -56,6 +55,8 @@ impl TodoManager {
|
||||
});
|
||||
}
|
||||
fn clear_completed(&self) {
|
||||
TODO_LIST.with(api).get()
|
||||
|
||||
self.0.modify(&TODO_LIST, move |list| {
|
||||
*list = list.drain().filter(|(_, item)| !item.checked).collect();
|
||||
})
|
||||
@@ -82,12 +83,12 @@ pub struct TodoItem {
|
||||
fn App(ctx: Context, props: &()) -> DomTree {
|
||||
init_recoil_root(ctx);
|
||||
|
||||
ctx.render(rsx! {
|
||||
rsx! { in ctx,
|
||||
div { id: "app", style { "{APP_STYLE}" }
|
||||
TodoList {}
|
||||
Footer {}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
@@ -109,7 +110,7 @@ pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
})
|
||||
});
|
||||
|
||||
ctx.render(rsx! {
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
header {
|
||||
class: "header"
|
||||
@@ -126,7 +127,7 @@ pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
// rsx! accepts optionals, so we suggest the `then` method in place of ternary
|
||||
{(!todos.is_empty()).then(|| rsx!( FilterToggles {}) )}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Props)]
|
||||
@@ -199,7 +200,7 @@ pub fn FilterToggles(ctx: Context, props: &()) -> DomTree {
|
||||
}
|
||||
|
||||
pub fn Footer(ctx: Context, props: &()) -> DomTree {
|
||||
rsx!( in ctx,
|
||||
rsx! { in ctx,
|
||||
footer {
|
||||
class: "info"
|
||||
p {"Double-click to edit a todo"}
|
||||
@@ -212,5 +213,5 @@ pub fn Footer(ctx: Context, props: &()) -> DomTree {
|
||||
a { "TodoMVC", href: "http://todomvc.com" }
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user