Debugging issues

This commit is contained in:
Greg Johnston 2022-08-10 22:42:54 -04:00
parent 612b64707e
commit 4a7154071e
6 changed files with 36 additions and 12 deletions

View file

@ -90,7 +90,7 @@ fn Counter(
prop:value={let value = value.clone(); move || value().to_string()} prop:value={let value = value.clone(); move || value().to_string()}
on:input=input on:input=input
/> */ /> */
//<span>{move || value().to_string()}</span> <span>{move || value().to_string()}</span>
<button on:click=move |_| set_value(|value| *value += 1)>"+1"</button> <button on:click=move |_| set_value(|value| *value += 1)>"+1"</button>
<button on:click=move |_| set_counters(|counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button> <button on:click=move |_| set_counters(|counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button>
</li> </li>

View file

@ -63,7 +63,7 @@ where
}); });
} }
pub fn create_component<'a, F, T>(cx: Scope, f: F) -> T pub fn create_component<F, T>(cx: Scope, f: F) -> T
where where
F: Fn() -> T, F: Fn() -> T,
T: IntoChild, T: IntoChild,

View file

@ -7,6 +7,7 @@ edition = "2021"
log = "0.4" log = "0.4"
slotmap = { version = "1", features = ["serde"] } slotmap = { version = "1", features = ["serde"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
debug-cell = "0.1"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2" wasm-bindgen = "0.2"

View file

@ -1,6 +1,9 @@
use crate::{Runtime, Scope, ScopeId, Source, Subscriber}; use crate::{Runtime, Scope, ScopeId, Source, Subscriber};
use debug_cell::RefCell;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{any::type_name, cell::RefCell, collections::HashSet, fmt::Debug, marker::PhantomData}; use std::{
any::type_name, /* cell::RefCell, */ collections::HashSet, fmt::Debug, marker::PhantomData,
};
impl Scope { impl Scope {
pub fn create_effect<T>(self, f: impl FnMut(Option<T>) -> T + 'static) -> Effect<T> pub fn create_effect<T>(self, f: impl FnMut(Option<T>) -> T + 'static) -> Effect<T>
@ -17,9 +20,9 @@ impl Scope {
ty: PhantomData, ty: PhantomData,
}; };
self.runtime /* self.runtime
.any_effect((self.id, id), |effect| effect.run((self.id, id))); .any_effect((self.id, id), |effect| effect.run((self.id, id)));
*/
eff eff
} }
} }
@ -92,8 +95,8 @@ where
type_name::<T>() type_name::<T>()
), ),
) )
.field("value", &self.value) //.field("value", &self.value)
.field("sources", &self.sources) //.field("sources", &self.sources)
.finish() .finish()
} }
} }

View file

@ -2,10 +2,11 @@ use crate::{
AnyEffect, AnyMemo, AnySignal, EffectId, EffectState, MemoId, MemoState, Runtime, SignalId, AnyEffect, AnyMemo, AnySignal, EffectId, EffectState, MemoId, MemoState, Runtime, SignalId,
SignalState, SignalState,
}; };
use debug_cell::RefCell;
use slotmap::SlotMap; use slotmap::SlotMap;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
cell::RefCell, /* cell::RefCell, */
collections::HashMap, collections::HashMap,
fmt::Debug, fmt::Debug,
}; };
@ -90,7 +91,6 @@ impl Debug for ScopeDisposer {
slotmap::new_key_type! { pub(crate) struct ScopeId; } slotmap::new_key_type! { pub(crate) struct ScopeId; }
#[derive(Debug)]
pub(crate) struct ScopeState { pub(crate) struct ScopeState {
pub(crate) parent: Option<Scope>, pub(crate) parent: Option<Scope>,
pub(crate) contexts: RefCell<HashMap<TypeId, Box<dyn Any>>>, pub(crate) contexts: RefCell<HashMap<TypeId, Box<dyn Any>>>,
@ -100,6 +100,12 @@ pub(crate) struct ScopeState {
pub(crate) effects: RefCell<SlotMap<EffectId, Box<dyn AnyEffect>>>, pub(crate) effects: RefCell<SlotMap<EffectId, Box<dyn AnyEffect>>>,
} }
impl Debug for ScopeState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ScopeState").finish()
}
}
impl ScopeState { impl ScopeState {
pub(crate) fn new(parent: Option<Scope>) -> Self { pub(crate) fn new(parent: Option<Scope>) -> Self {
Self { Self {

View file

@ -1,5 +1,6 @@
use crate::{Runtime, Scope, ScopeId, Source, Subscriber}; use crate::{Runtime, Scope, ScopeId, Source, Subscriber};
use std::{any::Any, cell::RefCell, collections::HashSet, fmt::Debug, marker::PhantomData}; use debug_cell::RefCell;
use std::{any::Any, /* cell::RefCell, */ collections::HashSet, fmt::Debug, marker::PhantomData,};
impl Scope { impl Scope {
pub fn create_signal<T>(self, value: T) -> (ReadSignal<T>, WriteSignal<T>) pub fn create_signal<T>(self, value: T) -> (ReadSignal<T>, WriteSignal<T>)
@ -212,13 +213,26 @@ where
slotmap::new_key_type! { pub(crate) struct SignalId; } slotmap::new_key_type! { pub(crate) struct SignalId; }
#[derive(Debug)] //#[derive(Debug)]
pub(crate) struct SignalState<T> { pub(crate) struct SignalState<T> {
value: RefCell<T>, value: RefCell<T>,
t_value: RefCell<Option<T>>, t_value: RefCell<Option<T>>,
subscribers: RefCell<HashSet<Subscriber>>, subscribers: RefCell<HashSet<Subscriber>>,
} }
impl<T> Debug for SignalState<T>
where
T: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SignalState")
.field("value", &*self.value.borrow())
.field("t_value", &*self.t_value.borrow())
.field("subscribers", &*self.subscribers.borrow())
.finish()
}
}
impl<T> SignalState<T> { impl<T> SignalState<T> {
pub fn new(value: T) -> Self { pub fn new(value: T) -> Self {
Self { Self {