use std::{hash::Hash, marker::PhantomData};
use super::{MapDiffSink, MapQuery, MapQueryInstall};
use crate::{
cell::CellImmutable,
cell_map::CellMap,
nested_map::NestedMap,
subscription::SubscriptionGuard,
traits::{CellValue, reactive_map::ReactiveMap},
};
impl<M> MapQueryInstall<M::Key, M::Value> for M
where
M: ReactiveMap + Clone,
M::Key: CellValue + Hash + Eq,
M::Value: CellValue,
{
fn install(self, sink: MapDiffSink<M::Key, M::Value>) -> Vec<SubscriptionGuard> {
let keepalive = self.clone();
let guard = self.subscribe_diffs_reactive(move |diff| {
let _ = &keepalive;
sink(diff);
});
vec![guard]
}
}
#[allow(private_bounds)]
impl<K, V, M> MapQuery<K, V> for CellMap<K, V, M>
where
K: CellValue + Hash + Eq,
V: CellValue,
M: Clone + Send + Sync + 'static,
{
fn materialize(self) -> CellMap<K, V, CellImmutable> {
CellMap {
inner: self.inner,
_marker: PhantomData,
}
}
}
#[allow(private_bounds)]
impl<PK, K, V> MapQuery<K, V> for NestedMap<PK, K, V>
where
PK: CellValue + Hash + Eq,
K: CellValue + Hash + Eq,
V: CellValue,
{
}