create tests for signals
This commit is contained in:
1 parent
b0d499036a
commit
717c09c4a3
8 files changed
+234
-5
No files matched your search
@@ -38,25 +38,25 @@ macro_rules! impls {
|
||||
|
||||
impl<T: Add<Output = T> + Copy + 'static> std::ops::AddAssign<T> for $ty<T> {
|
||||
fn add_assign(&mut self, rhs: T) {
|
||||
self.set(self.value() + rhs);
|
||||
self.with_mut(|v| *v = *v + rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Sub<Output = T> + Copy + 'static> std::ops::SubAssign<T> for $ty<T> {
|
||||
fn sub_assign(&mut self, rhs: T) {
|
||||
self.set(self.value() - rhs);
|
||||
self.with_mut(|v| *v = *v - rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Mul<Output = T> + Copy + 'static> std::ops::MulAssign<T> for $ty<T> {
|
||||
fn mul_assign(&mut self, rhs: T) {
|
||||
self.set(self.value() * rhs);
|
||||
self.with_mut(|v| *v = *v * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Div<Output = T> + Copy + 'static> std::ops::DivAssign<T> for $ty<T> {
|
||||
fn div_assign(&mut self, rhs: T) {
|
||||
self.set(self.value() / rhs);
|
||||
self.with_mut(|v| *v = *v / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,11 @@ impl<T: 'static> Signal<T> {
|
||||
pub fn read(&self) -> Ref<T> {
|
||||
let inner = self.inner.read();
|
||||
if let Some(current_scope_id) = current_scope_id() {
|
||||
log::trace!(
|
||||
"{:?} subscribed to {:?}",
|
||||
self.inner.value,
|
||||
current_scope_id
|
||||
);
|
||||
let mut subscribers = inner.subscribers.borrow_mut();
|
||||
if !subscribers.contains(¤t_scope_id) {
|
||||
subscribers.push(current_scope_id);
|
||||
@@ -98,6 +103,11 @@ impl<T: 'static> Signal<T> {
|
||||
{
|
||||
let inner = self.inner.read();
|
||||
for &scope_id in &*inner.subscribers.borrow() {
|
||||
log::trace!(
|
||||
"Write on {:?} triggered update on {:?}",
|
||||
self.inner.value,
|
||||
scope_id
|
||||
);
|
||||
(inner.update_any)(scope_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ fn owner_in_scope(scope: ScopeId) -> Rc<Owner> {
|
||||
}
|
||||
|
||||
pub struct CopyValue<T: 'static> {
|
||||
pub value: CopyHandle<T>,
|
||||
pub(crate) value: CopyHandle<T>,
|
||||
origin_scope: ScopeId,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user