Fix cargo test and a number of little cleanup bugs

This commit is contained in:
Jonathan Kelley committed 2024-01-30 17:33:14 -08:00
1 parent eff1dd6c90
commit 0bd9692e45
49 files changed
+307 -309

No files matched your search

+11 -11
View File
@@ -19,23 +19,23 @@ impl<R: Eq + Hash> Comparer<R> {
///
/// Generally, you shouldn't need to use this hook. Instead you can use [`crate::use_memo`]. If you have many values that you need to compare to a single value, this hook will change updates from O(n) to O(1) where n is the number of values you are comparing to.
pub fn new(mut f: impl FnMut() -> R + 'static) -> Comparer<R> {
let subscribers: CopyValue<FxHashMap<R, Signal<bool>>> =
let mut subscribers: CopyValue<FxHashMap<R, Signal<bool>>> =
CopyValue::new(FxHashMap::default());
let previous = CopyValue::new(None);
let mut previous = CopyValue::new(None);
Effect::new(move || {
let subscribers = subscribers.read();
let mut subscribers = subscribers.read();
let mut previous = previous.write();
if let Some(previous) = previous.take() {
if let Some(value) = subscribers.get(&previous) {
*value.write() = false;
if let Some(mut value) = subscribers.get(&previous).cloned() {
value.set(false)
}
}
let current = f();
if let Some(value) = subscribers.get(&current) {
if let Some(mut value) = subscribers.get(&current).cloned() {
*value.write() = true;
}
@@ -53,21 +53,21 @@ impl<R: Eq + Hash, S: Storage<SignalData<bool>>> Comparer<R, S> {
pub fn new_maybe_sync(mut f: impl FnMut() -> R + 'static) -> Comparer<R> {
let subscribers: CopyValue<FxHashMap<R, Signal<bool>>> =
CopyValue::new(FxHashMap::default());
let previous = CopyValue::new(None);
let mut previous = CopyValue::new(None);
Effect::new(move || {
let subscribers = subscribers.read();
let mut previous = previous.write();
if let Some(previous) = previous.take() {
if let Some(value) = subscribers.get(&previous) {
if let Some(mut value) = subscribers.get(&previous).cloned() {
*value.write() = false;
}
}
let current = f();
if let Some(value) = subscribers.get(&current) {
if let Some(mut value) = subscribers.get(&current).cloned() {
*value.write() = true;
}
@@ -78,8 +78,8 @@ impl<R: Eq + Hash, S: Storage<SignalData<bool>>> Comparer<R, S> {
}
/// Returns a signal which is true when the value is equal to the value passed to this function.
pub fn equal(&self, value: R) -> ReadOnlySignal<bool, S> {
let subscribers = self.subscribers.read();
pub fn equal(&mut self, value: R) -> ReadOnlySignal<bool, S> {
let mut subscribers = self.subscribers.write();
match subscribers.get(&value) {
Some(&signal) => signal.into(),