summaryrefslogtreecommitdiff
path: root/src/view/weak_links.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/weak_links.rs')
-rw-r--r--src/view/weak_links.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/view/weak_links.rs b/src/view/weak_links.rs
new file mode 100644
index 0000000..689c3c4
--- /dev/null
+++ b/src/view/weak_links.rs
@@ -0,0 +1,33 @@
+use std::cell::RefCell;
+use std::ops::Deref;
+use std::rc::Rc;
+use yew::prelude::*;
+
+/// Weak link; Useful for being able to have a list of subcomponents.
+pub struct WeakComponentLink<COMP: Component>(Rc<RefCell<Option<ComponentLink<COMP>>>>);
+
+impl<COMP: Component> Clone for WeakComponentLink<COMP> {
+ fn clone(&self) -> Self {
+ Self(Rc::clone(&self.0))
+ }
+}
+
+impl<COMP: Component> Default for WeakComponentLink<COMP> {
+ fn default() -> Self {
+ Self(Rc::default())
+ }
+}
+
+impl<COMP: Component> Deref for WeakComponentLink<COMP> {
+ type Target = Rc<RefCell<Option<ComponentLink<COMP>>>>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl<COMP: Component> PartialEq for WeakComponentLink<COMP> {
+ fn eq(&self, other: &Self) -> bool {
+ Rc::ptr_eq(&self.0, &other.0)
+ }
+}