Compare commits

..

No commits in common. "6037e5f519cdfef94210ee5577b5b81a6b30f0d2" and "5becc11bf9181de89490721ed07a97b8d649f1bb" have entirely different histories.

2 changed files with 9 additions and 59 deletions

View file

@ -1,7 +1,6 @@
use {
crate::{
view::{
Observer,
InnerViewPort, OuterViewPort, View, ViewPort,
singleton::SingletonView
},
@ -15,18 +14,18 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct SingletonBufferView<T: Clone + Send + Sync + 'static>(pub Arc<RwLock<T>>);
pub struct SingletonBufferView<T: Clone + Send + Sync + 'static>(Arc<RwLock<T>>);
impl<T> View for SingletonBufferView<T>
where
T: Clone + Send + Sync + 'static
T: Clone + Send + Sync + 'static,
{
type Msg = ();
}
impl<T> SingletonView for SingletonBufferView<T>
where
T: Clone + Send + Sync + 'static
T: Clone + Send + Sync + 'static,
{
type Item = T;
@ -40,39 +39,15 @@ where
#[derive(Clone)]
pub struct SingletonBuffer<T>
where
T: Clone + Send + Sync + 'static
T: Clone + Send + Sync + 'static,
{
pub value: Arc<RwLock<T>>,
pub port: InnerViewPort<dyn SingletonView<Item = T>>
}
pub struct SingletonBufferTarget<T>
where
T: Clone + Send + Sync + 'static
{
buffer: SingletonBuffer<T>,
src_view: Option<Arc<dyn SingletonView<Item = T>>>
}
impl<T> Observer< dyn SingletonView<Item = T> > for SingletonBufferTarget<T>
where
T: Clone + Send + Sync + 'static
{
fn notify(&mut self, _msg: &()) {
if let Some(v) = self.src_view.clone() {
self.buffer.set( v.get() );
}
}
fn reset(&mut self, view: Option<Arc<dyn SingletonView<Item = T>>>) {
self.src_view = view;
self.notify(&());
}
value: Arc<RwLock<T>>,
port: InnerViewPort<dyn SingletonView<Item = T>>
}
impl<T> SingletonBuffer<T>
where
T: Clone + Send + Sync + 'static
T: Clone + Send + Sync + 'static,
{
pub fn with_port(value: T, port: InnerViewPort<dyn SingletonView<Item = T>>) -> Self {
let value = Arc::new(RwLock::new(value));
@ -84,26 +59,6 @@ where
}
}
pub fn attach_to(&self, port: OuterViewPort<dyn SingletonView<Item = T>>) -> Arc<RwLock<SingletonBufferTarget<T>>> {
self.port.0.add_update_hook(Arc::new(port.0.clone()));
let target = Arc::new(RwLock::new(
SingletonBufferTarget {
buffer: self.clone(),
src_view: None
}
));
port.add_observer(target.clone());
target
}
pub fn make_in_port(&self) -> InnerViewPort<dyn SingletonView<Item = T>> {
let port = ViewPort::new();
self.attach_to(port.outer());
port.into_inner()
}
pub fn new(value: T) -> Self {
SingletonBuffer::with_port(value, ViewPort::new().into_inner())
}
@ -129,10 +84,6 @@ where
drop(v);
self.port.notify(&());
}
pub fn into_inner(self) -> Arc<RwLock<T>> {
self.value
}
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -107,7 +107,6 @@ where V::Msg: Clone
pub fn attach_to_port(&self, other_port: ViewPort<V>) {
self.set_view( other_port.view.read().unwrap().clone() );
other_port.add_observer( self.cast.clone() );
// todo: forward reset() ?
self.update_hooks.write().unwrap().clear();
self.add_update_hook( Arc::new(other_port) );
@ -304,10 +303,10 @@ impl<V: View + ?Sized + 'static> From<ViewPort<V>> for AnyViewPort {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
#[derive(Clone)]
pub struct AnyOuterViewPort(pub AnyViewPort);
pub struct AnyOuterViewPort(AnyViewPort);
#[derive(Clone)]
pub struct AnyInnerViewPort(pub AnyViewPort);
pub struct AnyInnerViewPort(AnyViewPort);
impl AnyOuterViewPort {
pub fn downcast<V: View + ?Sized + 'static>(self) -> Result<OuterViewPort<V>, AnyViewPort>