wip: doesnt share on thread

This commit is contained in:
Jonathan Kelley committed 2021-05-27 17:57:59 -04:00
1 parent ba975410f9
commit fe67ff9fa4
32 files changed
+1008 -575

No files matched your search

+3 -3
View File
@@ -29,9 +29,9 @@ impl TitleController {
fn main() {
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(|ctx, _| {
let title = use_recoil_value(ctx, &TITLE);
let subtitle = use_recoil_value(ctx, &SUBTITLE);
let controller = use_recoil_callback(ctx, TitleController::new);
let title = use_read(ctx, &TITLE);
let subtitle = use_read(ctx, &SUBTITLE);
let controller = use_recoil_api(ctx, TitleController::new);
rsx! { in ctx,
div {
+2 -2
View File
@@ -20,8 +20,8 @@ fn update_title(api: &RecoilApi) {
}
static App: FC<()> = |ctx, _| {
let title = use_recoil_value(ctx, &TITLE);
let next_light = use_recoil_callback(ctx, |api| move |_| update_title(&api));
let title = use_read(ctx, &TITLE);
let next_light = use_recoil_api(ctx, |api| move |_| update_title(&api));
rsx! { in ctx,
div {
+4 -2
View File
@@ -5,7 +5,7 @@
//! slicing up your state beyond atoms might be desirable.
//!
//! Instead of storing groups of entities in a collection of structs, the ECS Architecture instead stores
//! an array for each entity in the collection. This tends to improve performance for batch operations on
//! an array for each field in of a struct. This tends to improve performance for batch operations on
//! individual fields at the cost of complexity. Fortunately, this ECS model is built right into Recoil,
//! making it easier than ever to enable sharded datastructures in your app.
//!
@@ -16,6 +16,7 @@
//!
//! This approach is best suited for applications where individual entries in families are very large
//! and updates to neighbors are costly in terms of Clone or field comparisons for memoization.
use dioxus::prelude::*;
use dioxus_core as dioxus;
use recoil::*;
@@ -31,8 +32,9 @@ const TODOS: EcsModel<u32, TodoModel> = |builder| {};
// const SELECT_SUBTITLE: SelectorBorrowed<u32, &str> = |s, k| TODOS.field(1).select(k);
static App: FC<()> = |ctx, _| {
use_init_recoil_root(ctx, |_| {});
// let title = use_recoil_value(ctx, &C_SELECTOR);
dbg!(TODOS);
let title = "";
rsx! { in ctx,
+3 -4
View File
@@ -14,9 +14,8 @@ struct Todo {
}
static App: FC<()> = |ctx, _| {
use_init_recoil_root(ctx);
let todos = use_recoil_family(ctx, &TODOS);
use_init_recoil_root(ctx, |_| {});
let todos = use_read_family(ctx, &TODOS);
rsx! { in ctx,
div {
@@ -31,7 +30,7 @@ struct ChildProps {
}
static Child: FC<ChildProps> = |ctx, props| {
let (todo, set_todo) = use_recoil_state(ctx, &TODOS.select(&props.id));
let (todo, set_todo) = use_read_write(ctx, &TODOS.select(&props.id));
rsx! { in ctx,
div {
+3 -1
View File
@@ -4,7 +4,9 @@ use recoil::*;
const COUNT: Atom<i32> = |_| 0;
static App: FC<()> = |ctx, _| {
let (count, set_count) = use_recoil_state(ctx, &COUNT);
use_init_recoil_root(ctx, |_| {});
let (count, set_count) = use_read_write(ctx, &COUNT);
rsx! { in ctx,
div {
+3 -3
View File
@@ -18,10 +18,10 @@ const D_SELECTOR: SelectorFamilyBorrowed<i32, i32> = |api, key| -> &i32 {
};
static App: FC<()> = |ctx, _| {
use_init_recoil_root(ctx);
use_init_recoil_root(ctx, |_| {});
let title = use_read(ctx, &C_SELECTOR);
let title = use_recoil_value(ctx, &C_SELECTOR);
let title = "";
rsx! { in ctx,
div {
"{title}"
+4 -4
View File
@@ -6,7 +6,7 @@ const B: Atom<i32> = |_| 0;
const C: Selector<i32> = |api| api.get(&A) + api.get(&B);
static App: FC<()> = |ctx, _| {
use_init_recoil_root(ctx);
use_init_recoil_root(ctx, |_| {});
rsx! { in ctx,
div {
Banner {}
@@ -17,12 +17,12 @@ static App: FC<()> = |ctx, _| {
};
static Banner: FC<()> = |ctx, _| {
let count = use_recoil_value(ctx, &C);
let count = use_read(ctx, &C);
ctx.render(rsx! { h1 { "Count: {count}" } })
};
static BtnA: FC<()> = |ctx, _| {
let (a, set) = use_recoil_state(ctx, &A);
let (a, set) = use_read_write(ctx, &A);
rsx! { in ctx,
div { "a"
button { "+", onclick: move |_| set(a + 1) }
@@ -32,7 +32,7 @@ static BtnA: FC<()> = |ctx, _| {
};
static BtnB: FC<()> = |ctx, _| {
let (b, set) = use_recoil_state(ctx, &B);
let (b, set) = use_read_write(ctx, &B);
rsx! { in ctx,
div { "b"
button { "+", onclick: move |_| set(b + 1) }