diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-11 12:07:22 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-11 12:07:22 +0100 |
commit | 0660151a8b641fa0a23dde2598132029970f7ae4 (patch) | |
tree | 0bdeb1108419add4570f278795f0bfd0f5366856 /src/view/weak_links.rs | |
parent | 036a567bae8346eb38f9237f59645dbcc4f1cd8c (diff) | |
download | wasm-card-0660151a8b641fa0a23dde2598132029970f7ae4.tar.gz wasm-card-0660151a8b641fa0a23dde2598132029970f7ae4.tar.bz2 |
refactoring - reduced code size by about a third
Diffstat (limited to 'src/view/weak_links.rs')
-rw-r--r-- | src/view/weak_links.rs | 33 |
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) + } +} |