Use Input for ValueInvalidationSignal

This commit is contained in:
Shadowfacts 2024-11-02 19:21:30 -04:00
parent b79edeef0a
commit 8c761fe0d4
2 changed files with 5 additions and 8 deletions

View File

@ -117,7 +117,7 @@ impl<O: 'static, S: Synchronicity> GraphBuilder<O, S> {
) -> (Input<V>, ValueInvalidationSignal<V>) { ) -> (Input<V>, ValueInvalidationSignal<V>) {
let input = self.add_node(InvalidatableConstNode::new(value)); let input = self.add_node(InvalidatableConstNode::new(value));
let signal = ValueInvalidationSignal { let signal = ValueInvalidationSignal {
value: Rc::clone(&input.value), input: input.clone(),
signal: self.make_invalidation_signal(&input), signal: self.make_invalidation_signal(&input),
}; };
(input, signal) (input, signal)

View File

@ -333,17 +333,14 @@ impl Clone for InvalidationSignal {
/// ///
/// See [`GraphBuilder::add_invalidatable_value`]. /// See [`GraphBuilder::add_invalidatable_value`].
pub struct ValueInvalidationSignal<V> { pub struct ValueInvalidationSignal<V> {
value: Rc<RefCell<Option<V>>>, input: Input<V>,
signal: InvalidationSignal, signal: InvalidationSignal,
} }
impl<V: NodeValue> ValueInvalidationSignal<V> { impl<V: NodeValue> ValueInvalidationSignal<V> {
/// Get a reference to current value for the node corresponding to this signal. /// Get a reference to current value for the node corresponding to this signal.
pub fn value(&self) -> impl Deref<Target = V> + '_ { pub fn value(&self) -> impl Deref<Target = V> + '_ {
Ref::map(self.value.borrow(), |opt| { self.input.value()
opt.as_ref()
.expect("invalidatable value node must be initialized with value")
})
} }
/// Set a new value for the node corresponding to this signal. /// Set a new value for the node corresponding to this signal.
@ -352,7 +349,7 @@ impl<V: NodeValue> ValueInvalidationSignal<V> {
/// for the corresponding node. The graph will not be re-evaluated until [`Graph::evaluate`] or /// for the corresponding node. The graph will not be re-evaluated until [`Graph::evaluate`] or
/// [`Graph::evaluate_async`] is next called. /// [`Graph::evaluate_async`] is next called.
pub fn set_value(&self, value: V) { pub fn set_value(&self, value: V) {
let mut current_value = self.value.borrow_mut(); let mut current_value = self.input.value.borrow_mut();
if !current_value if !current_value
.as_ref() .as_ref()
.expect("invalidatable value node must be initialized with value") .expect("invalidatable value node must be initialized with value")
@ -367,7 +364,7 @@ impl<V: NodeValue> ValueInvalidationSignal<V> {
impl<V> Clone for ValueInvalidationSignal<V> { impl<V> Clone for ValueInvalidationSignal<V> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
value: Rc::clone(&self.value), input: self.input.clone(),
signal: self.signal.clone(), signal: self.signal.clone(),
} }
} }