change dioxus signal to generational box
This commit is contained in:
1 parent
190c65b15d
commit
84734c4146
5 files changed
+18
-18
No files matched your search
+2
-2
@@ -25,7 +25,7 @@ members = [
|
|||||||
"packages/native-core",
|
"packages/native-core",
|
||||||
"packages/native-core-macro",
|
"packages/native-core-macro",
|
||||||
"packages/rsx-rosetta",
|
"packages/rsx-rosetta",
|
||||||
"packages/copy",
|
"packages/generational_box",
|
||||||
"packages/signals",
|
"packages/signals",
|
||||||
"packages/hot-reload",
|
"packages/hot-reload",
|
||||||
"packages/fullstack",
|
"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" }
|
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
|
||||||
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
|
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
|
||||||
dioxus-signals = { path = "packages/signals" }
|
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-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
|
||||||
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
|
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
|
||||||
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }
|
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dioxus-copy"
|
name = "generational-box"
|
||||||
authors = ["Evan Almloff"]
|
authors = ["Evan Almloff"]
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@@ -106,8 +106,8 @@ fn panics() {
|
|||||||
fn fuzz() {
|
fn fuzz() {
|
||||||
fn maybe_owner_scope(
|
fn maybe_owner_scope(
|
||||||
store: &Store,
|
store: &Store,
|
||||||
valid_keys: &mut Vec<CopyHandle<String>>,
|
valid_keys: &mut Vec<GenerationalBox<String>>,
|
||||||
invalid_keys: &mut Vec<CopyHandle<String>>,
|
invalid_keys: &mut Vec<GenerationalBox<String>>,
|
||||||
path: &mut Vec<u8>,
|
path: &mut Vec<u8>,
|
||||||
) {
|
) {
|
||||||
let branch_cutoff = 5;
|
let branch_cutoff = 5;
|
||||||
@@ -145,14 +145,14 @@ fn fuzz() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CopyHandle<T> {
|
pub struct GenerationalBox<T> {
|
||||||
raw: MemoryLocation,
|
raw: MemoryLocation,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: u32,
|
generation: u32,
|
||||||
_marker: PhantomData<T>,
|
_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 {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
f.write_fmt(format_args!(
|
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)]
|
#[inline(always)]
|
||||||
fn validate(&self) -> bool {
|
fn validate(&self) -> bool {
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[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 {
|
fn clone(&self) -> 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 mut inner_mut = self.data.borrow_mut();
|
||||||
|
|
||||||
let raw = Box::new(value);
|
let raw = Box::new(value);
|
||||||
let old = inner_mut.replace(raw);
|
let old = inner_mut.replace(raw);
|
||||||
assert!(old.is_none());
|
assert!(old.is_none());
|
||||||
CopyHandle {
|
GenerationalBox {
|
||||||
raw: *self,
|
raw: *self,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: self.generation.get(),
|
generation: self.generation.get(),
|
||||||
@@ -316,7 +316,7 @@ pub struct Owner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 mut location = self.store.claim();
|
||||||
let key = location.replace(value);
|
let key = location.replace(value);
|
||||||
self.owned.borrow_mut().push(location);
|
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.
|
/// 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();
|
let location = self.store.claim();
|
||||||
CopyHandle {
|
GenerationalBox {
|
||||||
raw: location,
|
raw: location,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: location.generation.get(),
|
generation: location.generation.get(),
|
||||||
@@ -8,7 +8,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus-core = { workspace = true }
|
dioxus-core = { workspace = true }
|
||||||
dioxus-copy = { workspace = true }
|
generational-box = { workspace = true }
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
simple_logger = "4.2.0"
|
simple_logger = "4.2.0"
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use dioxus_core::prelude::{
|
|||||||
};
|
};
|
||||||
use dioxus_core::ScopeId;
|
use dioxus_core::ScopeId;
|
||||||
|
|
||||||
use dioxus_copy::{CopyHandle, Owner, Store};
|
use generational_box::{GenerationalBox, Owner, Store};
|
||||||
|
|
||||||
fn current_store() -> Store {
|
fn current_store() -> Store {
|
||||||
match consume_context() {
|
match consume_context() {
|
||||||
@@ -41,7 +41,7 @@ fn owner_in_scope(scope: ScopeId) -> Rc<Owner> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CopyValue<T: 'static> {
|
pub struct CopyValue<T: 'static> {
|
||||||
pub(crate) value: CopyHandle<T>,
|
pub(crate) value: GenerationalBox<T>,
|
||||||
origin_scope: ScopeId,
|
origin_scope: ScopeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user