Skip to content

Commit 77539fe

Browse files
committed
- Refactored the Signal class, removing the dependency on the mvvm library
- Adjusted the project package name and republished
1 parent c522681 commit 77539fe

File tree

6 files changed

+37
-61
lines changed

6 files changed

+37
-61
lines changed

Cargo.lock

Lines changed: 3 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# ReactiveCache
22
**Cache smart, update only when it matters.**
33

4-
[![Crates.io](https://img.shields.io/crates/v/reactive_cache.svg)](https://crates.io/crates/reactive_cache)
5-
[![Docs.rs](https://docs.rs/reactive_cache/badge.svg)](https://docs.rs/reactive_cache)
6-
[![License](https://img.shields.io/crates/l/reactive_cache.svg)](LICENSE)
4+
[![Crates.io](https://img.shields.io/crates/v/reactive-cache.svg)](https://crates.io/crates/reactive-cache)
5+
[![Docs.rs](https://docs.rs/reactive-cache/badge.svg)](https://docs.rs/reactive-cache)
6+
[![License](https://img.shields.io/crates/l/reactive-cache.svg)](LICENSE)
77

88
A lightweight, dependency-aware memoization library with automatic invalidation and lazy recomputation.
99

cache/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "reactive_cache"
2+
name = "reactive-cache"
33
version = "0.1.0"
44
edition = "2024"
55
description = "A lightweight, dependency-aware memoization library with automatic invalidation and lazy recomputation."
@@ -10,5 +10,4 @@ categories = ["caching"]
1010

1111
[dependencies]
1212
lru = "0.16.0"
13-
mvvm = "0.2.1"
1413
once_cell = "1.21.3"

cache/src/signal.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ use std::{
33
rc::{Rc, Weak},
44
};
55

6-
use mvvm::System::ComponentModel::ObservableProperty;
7-
86
use crate::{Effect, Observable, call_stack};
97

108
pub struct Signal<T>
119
where
1210
T: Eq + Default + 'static,
1311
{
14-
prop: ObservableProperty<'static, T>,
12+
value: RefCell<T>,
1513
dependents: RefCell<Vec<&'static dyn Observable>>,
1614
effects: RefCell<Vec<Weak<Effect>>>,
1715
}
@@ -35,28 +33,22 @@ where
3533
});
3634
}
3735

38-
pub fn new(value: Option<T>) -> Rc<Self> {
39-
let s = Rc::new(Signal {
40-
prop: value.map_or_else(Default::default, ObservableProperty::new),
41-
dependents: vec![].into(),
42-
effects: vec![].into(),
43-
});
44-
45-
let weak = Rc::downgrade(&s);
46-
s.prop.PropertyChanging.borrow_mut().add(move |_| {
47-
if let Some(s) = weak.upgrade() {
48-
s.invalidate();
49-
}
50-
});
36+
#[allow(non_snake_case)]
37+
fn OnPropertyChanged(&self) {
38+
self.flush_effects()
39+
}
5140

52-
let weak = Rc::downgrade(&s);
53-
s.prop.PropertyChanged.borrow_mut().add(move |_| {
54-
if let Some(s) = weak.upgrade() {
55-
s.flush_effects();
56-
}
57-
});
41+
#[allow(non_snake_case)]
42+
fn OnPropertyChanging(&self) {
43+
self.invalidate()
44+
}
5845

59-
s
46+
pub fn new(value: Option<T>) -> Self {
47+
Signal {
48+
value: value.unwrap_or_default().into(),
49+
dependents: vec![].into(),
50+
effects: vec![].into(),
51+
}
6052
}
6153

6254
pub fn get(&self) -> Ref<'_, T> {
@@ -79,10 +71,20 @@ where
7971
self.effects.borrow_mut().push(Rc::downgrade(&e));
8072
}
8173

82-
self.prop.GetValue()
74+
self.value.borrow()
8375
}
8476

8577
pub fn set(&self, value: T) -> bool {
86-
self.prop.SetValue(value)
78+
if *self.value.borrow() == value {
79+
return false;
80+
}
81+
82+
self.OnPropertyChanging();
83+
84+
*self.value.borrow_mut() = value;
85+
86+
self.OnPropertyChanged();
87+
88+
true
8789
}
8890
}

macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "reactive_macros"
2+
name = "reactive-macros"
33
version = "0.1.0"
44
edition = "2024"
55
description = "A lightweight, dependency-aware memoization library with automatic invalidation and lazy recomputation."
@@ -17,4 +17,4 @@ proc-macro2 = "1.0.95"
1717
quote = "1.0.40"
1818
syn = { version = "2.0.104", features = ["full"] }
1919

20-
reactive_cache = { path = "../cache" }
20+
reactive-cache = { path = "../cache" }

macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn signal(input: TokenStream) -> TokenStream {
3232
let ident_set = format_ident!("{}_set", ident);
3333
let ident_fn = format_ident!("{}", ident);
3434

35-
let lazy_ty = quote! { once_cell::unsync::Lazy<std::rc::Rc<reactive_cache::Signal<#ty>>> };
35+
let lazy_ty = quote! { once_cell::unsync::Lazy<reactive_cache::Signal<#ty>> };
3636
let expr = quote! { once_cell::unsync::Lazy::new(|| reactive_cache::Signal::new(Some(#expr))) };
3737

3838
let expanded = quote! {

0 commit comments

Comments
 (0)