feat: mvoe away from compound context

This commit is contained in:
Jonathan Kelley committed 2021-09-21 13:42:52 -04:00
1 parent bfdcb20437
commit a2c7d17b05
103 files changed
+309 -293

No files matched your search

+4 -4
View File
@@ -22,7 +22,7 @@ criterion_group!(mbenches, create_rows);
criterion_main!(mbenches);
fn create_rows(c: &mut Criterion) {
static App: FC<()> = |cx| {
static App: FC<()> = |cx, props| {
let mut rng = SmallRng::from_entropy();
let rows = (0..10_000).map(|f| {
let label = Label::new(&mut rng);
@@ -56,11 +56,11 @@ struct RowProps {
row_id: usize,
label: Label,
}
fn Row<'a>(cx: Context<'a, RowProps>) -> DomTree {
let [adj, col, noun] = cx.label.0;
fn Row<'a>(cx: Context<'a>, props: &RowProps) -> DomTree<'a> {
let [adj, col, noun] = props.label.0;
cx.render(rsx! {
tr {
td { class:"col-md-1", "{cx.row_id}" }
td { class:"col-md-1", "{props.row_id}" }
td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
a { class: "lbl", "{adj}" "{col}" "{noun}" }
}
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus_core::prelude::*;
fn main() {}
pub static Example: FC<()> = |cx| {
pub static Example: FC<()> = |cx, props| {
let list = (0..10).map(|_f| LazyNodes::new(move |_f| todo!()));
cx.render(LazyNodes::new(move |cx| {
+3 -3
View File
@@ -2,7 +2,7 @@ use dioxus_core::prelude::*;
fn main() {}
const App: FC<()> = |cx| {
const App: FC<()> = |cx, props| {
// create a new future
let _fut = cx.use_hook(
|_| {
@@ -20,7 +20,7 @@ const App: FC<()> = |cx| {
todo!()
};
const Task: FC<()> = |cx| {
const Task: FC<()> = |cx, props| {
let (_task, _res) = use_task(cx, || async { true });
// task.pause();
// task.restart();
@@ -34,6 +34,6 @@ const Task: FC<()> = |cx| {
todo!()
};
fn use_mut<P, T>(_cx: Context<P>, _f: impl FnOnce() -> T) -> &mut T {
fn use_mut<P, T>(_cx: Context, _f: impl FnOnce() -> T) -> &mut T {
todo!()
}
+2 -2
View File
@@ -20,7 +20,7 @@ struct ListItem {
age: u32,
}
fn app(cx: Context<AppProps>) -> DomTree {
fn app<'a>(cx: Context<'a>, props: &AppProps) -> DomTree<'a> {
// let (val, set_val) = use_state_classic(cx, || 0);
cx.render(LazyNodes::new(move |_nodecx| {
@@ -56,7 +56,7 @@ struct ChildProps {
item_handler: Rc<dyn Fn(i32)>,
}
fn ChildItem<'a>(cx: Context<'a, ChildProps>) -> DomTree {
fn ChildItem<'a>(cx: Context<'a>, props: &'a ChildProps) -> DomTree<'a> {
cx.render(LazyNodes::new(move |__cx| todo!()))
}
+1 -1
View File
@@ -6,7 +6,7 @@ struct SomeContext {
}
#[allow(unused)]
static Example: FC<()> = |cpt| {
static Example: FC<()> = |cx, props| {
todo!()
// let value = cx.use_context(|c: &SomeContext| c.items.last().unwrap());
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus_core::prelude::*;
fn main() {}
fn app(cx: Context<()>) -> DomTree {
fn app<'a>(cx: Context<'a>, props: &()) -> DomTree<'a> {
let vak = use_suspense(
cx,
|| async {},
+4 -4
View File
@@ -10,7 +10,7 @@ fn main() {
assert!(g.edits.len() > 1);
}
static App: FC<()> = |cx| {
static App: FC<()> = |cx, props| {
let mut rng = SmallRng::from_entropy();
let rows = (0..10_000).map(|f| {
let label = Label::new(&mut rng);
@@ -35,12 +35,12 @@ struct RowProps {
row_id: usize,
label: Label,
}
fn Row<'a>(cx: Context<'a, RowProps>) -> DomTree {
fn Row<'a>(cx: Context<'a>, props: &'a RowProps) -> DomTree<'a> {
cx.render(rsx! {
tr {
td { class:"col-md-1", "{cx.row_id}" }
td { class:"col-md-1", "{props.row_id}" }
td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
a { class: "lbl", "{cx.label}" }
a { class: "lbl", "{props.label}" }
}
td { class: "col-md-1"
a { class: "remove", onclick: move |_| {/* remove */}
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus_core::prelude::*;
#[async_std::main]
async fn main() {
static App: FC<()> = |cx| cx.render(LazyNodes::new(|f| f.text(format_args!("hello"))));
static App: FC<()> = |cx, props|cx.render(LazyNodes::new(|f| f.text(format_args!("hello"))));
let mut dom = VirtualDom::new(App);
+4 -4
View File
@@ -68,7 +68,7 @@ impl<'src> Context<'src> {
/// ## Example
///
/// ```rust
/// const App: FC<()> = |cx| {
/// const App: FC<()> = |cx, props|{
/// cx.render(rsx!{
/// CustomCard {
/// h1 {}
@@ -77,7 +77,7 @@ impl<'src> Context<'src> {
/// })
/// }
///
/// const CustomCard: FC<()> = |cx| {
/// const CustomCard: FC<()> = |cx, props|{
/// cx.render(rsx!{
/// div {
/// h1 {"Title card"}
@@ -176,12 +176,12 @@ impl<'src> Context<'src> {
/// ```
/// struct SharedState(&'static str);
///
/// static App: FC<()> = |cx| {
/// static App: FC<()> = |cx, props|{
/// cx.use_provide_state(|| SharedState("world"));
/// rsx!(cx, Child {})
/// }
///
/// static Child: FC<()> = |cx| {
/// static Child: FC<()> = |cx, props|{
/// let state = cx.use_consume_state::<SharedState>();
/// rsx!(cx, div { "hello {state.0}" })
/// }
+4 -4
View File
@@ -58,7 +58,7 @@ impl Scope {
///
/// # Example
/// ```rust
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -78,7 +78,7 @@ impl Scope {
/// # Example
///
/// ```rust
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -98,7 +98,7 @@ impl Scope {
/// # Example
///
/// ```rust
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -116,7 +116,7 @@ impl Scope {
/// # Example
///
/// ```rust
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
/// dom.rebuild();
/// let base = dom.base_scope();
///
+5 -5
View File
@@ -31,7 +31,7 @@ use std::any::Any;
///
/// Example
/// ```rust
/// static App: FC<()> = |cx| {
/// static App: FC<()> = |cx, props|{
/// cx.render(rsx!{
/// div {
/// "Hello World"
@@ -180,7 +180,7 @@ impl VirtualDom {
/// struct AppProps {
/// route: &'static str
/// }
/// static App: FC<AppProps> = |cx| cx.render(rsx!{ "route is {cx.route}" });
/// static App: FC<AppProps> = |cx, props|cx.render(rsx!{ "route is {cx.route}" });
///
/// let mut dom = VirtualDom::new_with_props(App, AppProps { route: "start" });
///
@@ -227,7 +227,7 @@ impl VirtualDom {
///
/// # Example
/// ```
/// static App: FC<()> = |cx| cx.render(rsx!{ "hello world" });
/// static App: FC<()> = |cx, props|cx.render(rsx!{ "hello world" });
/// let mut dom = VirtualDom::new();
/// let edits = dom.rebuild();
///
@@ -252,7 +252,7 @@ impl VirtualDom {
/// value: Shared<&'static str>,
/// }
///
/// static App: FC<AppProps> = |cx| {
/// static App: FC<AppProps> = |cx, props|{
/// let val = cx.value.borrow();
/// cx.render(rsx! { div { "{val}" } })
/// };
@@ -314,7 +314,7 @@ impl VirtualDom {
/// # Example
///
/// ```no_run
/// static App: FC<()> = |cx| rsx!(cx, div {"hello"} );
/// static App: FC<()> = |cx, props|rsx!(cx, div {"hello"} );
/// let mut dom = VirtualDom::new(App);
/// loop {
/// let deadline = TimeoutFuture::from_ms(16);
+1 -1
View File
@@ -10,7 +10,7 @@ type Shared<T> = Rc<RefCell<T>>;
#[test]
fn sample_refs() {
// static App: FC<()> = |cx| {
// static App: FC<()> = |cx, props|{
// let div_ref = use_node_ref::<MyRef, _>(cx);
// cx.render(rsx! {