change dioxus signal to generational box

This commit is contained in:
Evan Almloff 2023-08-07 14:34:16 -07:00
parent 190c65b15d
commit 84734c4146
5 changed files with 18 additions and 18 deletions

View file

@ -25,7 +25,7 @@ members = [
"packages/native-core",
"packages/native-core-macro",
"packages/rsx-rosetta",
"packages/copy",
"packages/generational_box",
"packages/signals",
"packages/hot-reload",
"packages/fullstack",
@ -77,7 +77,7 @@ dioxus-native-core = { path = "packages/native-core", version = "0.4.0" }
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
dioxus-signals = { path = "packages/signals" }
dioxus-copy = { path = "packages/copy" }
generational-box = { path = "packages/generational_box" }
dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }

View file

@ -1,5 +1,5 @@
[package]
name = "dioxus-copy"
name = "generational-box"
authors = ["Evan Almloff"]
version = "0.0.0"
edition = "2018"

View file

@ -106,8 +106,8 @@ fn panics() {
fn fuzz() {
fn maybe_owner_scope(
store: &Store,
valid_keys: &mut Vec<CopyHandle<String>>,
invalid_keys: &mut Vec<CopyHandle<String>>,
valid_keys: &mut Vec<GenerationalBox<String>>,
invalid_keys: &mut Vec<GenerationalBox<String>>,
path: &mut Vec<u8>,
) {
let branch_cutoff = 5;
@ -145,14 +145,14 @@ fn fuzz() {
}
}
pub struct CopyHandle<T> {
pub struct GenerationalBox<T> {
raw: MemoryLocation,
#[cfg(any(debug_assertions, feature = "check_generation"))]
generation: u32,
_marker: PhantomData<T>,
}
impl<T: 'static> Debug for CopyHandle<T> {
impl<T: 'static> Debug for GenerationalBox<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[cfg(any(debug_assertions, feature = "check_generation"))]
f.write_fmt(format_args!(
@ -166,7 +166,7 @@ impl<T: 'static> Debug for CopyHandle<T> {
}
}
impl<T: 'static> CopyHandle<T> {
impl<T: 'static> GenerationalBox<T> {
#[inline(always)]
fn validate(&self) -> bool {
#[cfg(any(debug_assertions, feature = "check_generation"))]
@ -227,9 +227,9 @@ impl<T: 'static> CopyHandle<T> {
}
}
impl<T> Copy for CopyHandle<T> {}
impl<T> Copy for GenerationalBox<T> {}
impl<T> Clone for CopyHandle<T> {
impl<T> Clone for GenerationalBox<T> {
fn clone(&self) -> Self {
*self
}
@ -253,13 +253,13 @@ impl MemoryLocation {
}
}
fn replace<T: 'static>(&mut self, value: T) -> CopyHandle<T> {
fn replace<T: 'static>(&mut self, value: T) -> GenerationalBox<T> {
let mut inner_mut = self.data.borrow_mut();
let raw = Box::new(value);
let old = inner_mut.replace(raw);
assert!(old.is_none());
CopyHandle {
GenerationalBox {
raw: *self,
#[cfg(any(debug_assertions, feature = "check_generation"))]
generation: self.generation.get(),
@ -316,7 +316,7 @@ pub struct Owner {
}
impl Owner {
pub fn insert<T: 'static>(&self, value: T) -> CopyHandle<T> {
pub fn insert<T: 'static>(&self, value: T) -> GenerationalBox<T> {
let mut location = self.store.claim();
let key = location.replace(value);
self.owned.borrow_mut().push(location);
@ -324,9 +324,9 @@ impl Owner {
}
/// Creates an invalid handle. This is useful for creating a handle that will be filled in later. If you use this before the value is filled in, you will get may get a panic or an out of date value.
pub fn invalid<T: 'static>(&self) -> CopyHandle<T> {
pub fn invalid<T: 'static>(&self) -> GenerationalBox<T> {
let location = self.store.claim();
CopyHandle {
GenerationalBox {
raw: location,
#[cfg(any(debug_assertions, feature = "check_generation"))]
generation: location.generation.get(),

View file

@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
dioxus-core = { workspace = true }
dioxus-copy = { workspace = true }
generational-box = { workspace = true }
log.workspace = true
simple_logger = "4.2.0"

View file

@ -8,7 +8,7 @@ use dioxus_core::prelude::{
};
use dioxus_core::ScopeId;
use dioxus_copy::{CopyHandle, Owner, Store};
use generational_box::{GenerationalBox, Owner, Store};
fn current_store() -> Store {
match consume_context() {
@ -41,7 +41,7 @@ fn owner_in_scope(scope: ScopeId) -> Rc<Owner> {
}
pub struct CopyValue<T: 'static> {
pub(crate) value: CopyHandle<T>,
pub(crate) value: GenerationalBox<T>,
origin_scope: ScopeId,
}