Revert "fix: use typeid of atoms for their unique ID (#558)"
This reverts commit bf9901a6cd.
This commit is contained in:
4 files changed
+11
-38
No files matched your search
@@ -3,7 +3,7 @@ use crate::{AtomId, AtomRoot, Readable, Writable};
|
|||||||
pub type Atom<T> = fn(AtomBuilder) -> T;
|
pub type Atom<T> = fn(AtomBuilder) -> T;
|
||||||
pub struct AtomBuilder;
|
pub struct AtomBuilder;
|
||||||
|
|
||||||
impl<V: 'static> Readable<V> for Atom<V> {
|
impl<V> Readable<V> for Atom<V> {
|
||||||
fn read(&self, _root: AtomRoot) -> Option<V> {
|
fn read(&self, _root: AtomRoot) -> Option<V> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -11,14 +11,11 @@ impl<V: 'static> Readable<V> for Atom<V> {
|
|||||||
(*self)(AtomBuilder)
|
(*self)(AtomBuilder)
|
||||||
}
|
}
|
||||||
fn unique_id(&self) -> AtomId {
|
fn unique_id(&self) -> AtomId {
|
||||||
AtomId {
|
*self as *const ()
|
||||||
ptr: *self as *const (),
|
|
||||||
type_id: std::any::TypeId::of::<V>(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: 'static> Writable<V> for Atom<V> {
|
impl<V> Writable<V> for Atom<V> {
|
||||||
fn write(&self, _root: AtomRoot, _value: V) {
|
fn write(&self, _root: AtomRoot, _value: V) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use im_rc::HashMap as ImMap;
|
|||||||
pub struct AtomFamilyBuilder;
|
pub struct AtomFamilyBuilder;
|
||||||
pub type AtomFamily<K, V> = fn(AtomFamilyBuilder) -> ImMap<K, V>;
|
pub type AtomFamily<K, V> = fn(AtomFamilyBuilder) -> ImMap<K, V>;
|
||||||
|
|
||||||
impl<K, V: 'static> Readable<ImMap<K, V>> for AtomFamily<K, V> {
|
impl<K, V> Readable<ImMap<K, V>> for AtomFamily<K, V> {
|
||||||
fn read(&self, _root: AtomRoot) -> Option<ImMap<K, V>> {
|
fn read(&self, _root: AtomRoot) -> Option<ImMap<K, V>> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -14,14 +14,11 @@ impl<K, V: 'static> Readable<ImMap<K, V>> for AtomFamily<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unique_id(&self) -> AtomId {
|
fn unique_id(&self) -> AtomId {
|
||||||
AtomId {
|
*self as *const ()
|
||||||
ptr: *self as *const (),
|
|
||||||
type_id: std::any::TypeId::of::<V>(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V: 'static> Writable<ImMap<K, V>> for AtomFamily<K, V> {
|
impl<K, V> Writable<ImMap<K, V>> for AtomFamily<K, V> {
|
||||||
fn write(&self, _root: AtomRoot, _value: ImMap<K, V>) {
|
fn write(&self, _root: AtomRoot, _value: ImMap<K, V>) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::cell::RefCell;
|
|||||||
pub struct AtomRefBuilder;
|
pub struct AtomRefBuilder;
|
||||||
pub type AtomRef<T> = fn(AtomRefBuilder) -> T;
|
pub type AtomRef<T> = fn(AtomRefBuilder) -> T;
|
||||||
|
|
||||||
impl<V: 'static> Readable<RefCell<V>> for AtomRef<V> {
|
impl<V> Readable<RefCell<V>> for AtomRef<V> {
|
||||||
fn read(&self, _root: AtomRoot) -> Option<RefCell<V>> {
|
fn read(&self, _root: AtomRoot) -> Option<RefCell<V>> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -14,10 +14,7 @@ impl<V: 'static> Readable<RefCell<V>> for AtomRef<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unique_id(&self) -> AtomId {
|
fn unique_id(&self) -> AtomId {
|
||||||
AtomId {
|
*self as *const ()
|
||||||
ptr: *self as *const (),
|
|
||||||
type_id: std::any::TypeId::of::<V>(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
use std::{
|
use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
|
||||||
any::{Any, TypeId},
|
|
||||||
cell::RefCell,
|
|
||||||
collections::HashMap,
|
|
||||||
rc::Rc,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use dioxus_core::ScopeId;
|
use dioxus_core::ScopeId;
|
||||||
use im_rc::HashSet;
|
use im_rc::HashSet;
|
||||||
|
|
||||||
use crate::Readable;
|
use crate::Readable;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
pub type AtomId = *const ();
|
||||||
pub struct AtomId {
|
|
||||||
pub ptr: *const (),
|
|
||||||
pub type_id: TypeId,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AtomRoot {
|
pub struct AtomRoot {
|
||||||
pub atoms: RefCell<HashMap<AtomId, Slot>>,
|
pub atoms: RefCell<HashMap<AtomId, Slot>>,
|
||||||
@@ -54,15 +44,7 @@ impl AtomRoot {
|
|||||||
// initialize the value if it's not already initialized
|
// initialize the value if it's not already initialized
|
||||||
if let Some(slot) = atoms.get_mut(&f.unique_id()) {
|
if let Some(slot) = atoms.get_mut(&f.unique_id()) {
|
||||||
slot.subscribers.insert(scope);
|
slot.subscribers.insert(scope);
|
||||||
match slot.value.clone().downcast() {
|
slot.value.clone().downcast().unwrap()
|
||||||
Ok(res) => res,
|
|
||||||
Err(e) => panic!(
|
|
||||||
"Downcasting atom failed: {:?}. Has typeid of {:?} but needs typeid of {:?}",
|
|
||||||
f.unique_id(),
|
|
||||||
e.type_id(),
|
|
||||||
TypeId::of::<V>()
|
|
||||||
),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let value = Rc::new(f.init());
|
let value = Rc::new(f.init());
|
||||||
let mut subscribers = HashSet::new();
|
let mut subscribers = HashSet::new();
|
||||||
|
|||||||
Reference in new issue
Block a user