fix: allow fermi atomref to be cloned
This commit is contained in:
1 parent
f67b71c5a5
commit
70a6f95c8c
2 files changed
+36
No files matched your search
@@ -14,6 +14,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div { "hello {name}!" }
|
div { "hello {name}!" }
|
||||||
Child {}
|
Child {}
|
||||||
|
ChildWithRef{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,3 +28,27 @@ fn Child(cx: Scope) -> Element {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NAMES: AtomRef<Vec<String>> = |_| vec!["world".to_string()];
|
||||||
|
|
||||||
|
fn ChildWithRef(cx: Scope) -> Element {
|
||||||
|
let names = use_atom_ref(&cx, NAMES);
|
||||||
|
|
||||||
|
cx.render(rsx! {
|
||||||
|
div {
|
||||||
|
ul {
|
||||||
|
names.read().iter().map(|f| rsx!{
|
||||||
|
li { "hello: {f}" }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
onclick: move |_| {
|
||||||
|
let names = names.clone();
|
||||||
|
cx.spawn(async move {
|
||||||
|
names.write().push("asd".to_string());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -34,6 +34,17 @@ pub struct UseAtomRef<T> {
|
|||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Clone for UseAtomRef<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
ptr: self.ptr,
|
||||||
|
value: self.value.clone(),
|
||||||
|
root: self.root.clone(),
|
||||||
|
scope_id: self.scope_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: 'static> UseAtomRef<T> {
|
impl<T: 'static> UseAtomRef<T> {
|
||||||
pub fn read(&self) -> Ref<T> {
|
pub fn read(&self) -> Ref<T> {
|
||||||
self.value.borrow()
|
self.value.borrow()
|
||||||
|
|||||||
Reference in new issue
Block a user