mirror of
https://github.com/Zenithsiz/dynatos.git
synced 2026-02-03 18:13:04 +00:00
Moved enum_split::SignalStorage to it's own module.
This commit is contained in:
parent
5728d63ab7
commit
0a53e6421b
@ -3,11 +3,13 @@
|
||||
// Modules
|
||||
mod ctx;
|
||||
mod either;
|
||||
mod storage;
|
||||
|
||||
// Exports
|
||||
pub use self::{
|
||||
ctx::EnumSplitValueUpdateCtx,
|
||||
either::{All1, All2, All3, Either1, Either2, Either3},
|
||||
storage::SignalStorage,
|
||||
};
|
||||
|
||||
// Imports
|
||||
@ -121,36 +123,6 @@ impl<S, T: EnumSplitValue<S, W>, W: EnumSplitWorld<S, T>> SignalBorrow for EnumS
|
||||
|
||||
impl<S, T: EnumSplitValue<S, W>, W: EnumSplitWorld<S, T>> SignalWithDefaultImpl for EnumSplitSignal<S, T, W> {}
|
||||
|
||||
/// Signal storage.
|
||||
#[derive(Debug)]
|
||||
pub struct SignalStorage<T> {
|
||||
/// Signal
|
||||
// TODO: Allow the user to specify another type of signal?
|
||||
signal: Signal<T>,
|
||||
|
||||
/// Write-back effect
|
||||
// TODO: Not use dynamic dispatch here
|
||||
write_back_effect: Effect<dyn EffectRun>,
|
||||
}
|
||||
|
||||
impl<T> SignalStorage<T> {
|
||||
/// Clones the signal in storage
|
||||
#[must_use]
|
||||
pub fn signal(&self) -> Signal<T> {
|
||||
self.signal.clone()
|
||||
}
|
||||
|
||||
/// Sets the value of the signal in storage.
|
||||
///
|
||||
/// Suppresses the write-back effect during.
|
||||
pub fn set(&self, new_value: T)
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.write_back_effect.suppressed(|| self.signal.set(new_value));
|
||||
}
|
||||
}
|
||||
|
||||
/// Effect fn inner
|
||||
struct EffectFnInner<S, T: EnumSplitValue<S, W>, W: ReactiveWorld> {
|
||||
/// Signals
|
||||
|
||||
@ -51,9 +51,6 @@ impl<'a, S, W: ReactiveWorld> EnumSplitValueUpdateCtx<'a, S, W> {
|
||||
signal.with(|_| ());
|
||||
});
|
||||
|
||||
SignalStorage {
|
||||
signal,
|
||||
write_back_effect,
|
||||
}
|
||||
SignalStorage::new(signal, write_back_effect)
|
||||
}
|
||||
}
|
||||
|
||||
42
dynatos-reactive/src/enum_split/storage.rs
Normal file
42
dynatos-reactive/src/enum_split/storage.rs
Normal file
@ -0,0 +1,42 @@
|
||||
//! Storage
|
||||
|
||||
// Imports
|
||||
use crate::{Effect, EffectRun, Signal, SignalSet};
|
||||
|
||||
/// Signal storage.
|
||||
#[derive(Debug)]
|
||||
pub struct SignalStorage<T> {
|
||||
/// Signal
|
||||
// TODO: Allow the user to specify another type of signal?
|
||||
signal: Signal<T>,
|
||||
|
||||
/// Write-back effect
|
||||
// TODO: Not use dynamic dispatch here
|
||||
write_back_effect: Effect<dyn EffectRun>,
|
||||
}
|
||||
|
||||
impl<T> SignalStorage<T> {
|
||||
/// Creates a new signal storage
|
||||
pub(crate) fn new(signal: Signal<T>, write_back_effect: Effect<dyn EffectRun>) -> Self {
|
||||
Self {
|
||||
signal,
|
||||
write_back_effect,
|
||||
}
|
||||
}
|
||||
|
||||
/// Clones the signal in storage
|
||||
#[must_use]
|
||||
pub fn signal(&self) -> Signal<T> {
|
||||
self.signal.clone()
|
||||
}
|
||||
|
||||
/// Sets the value of the signal in storage.
|
||||
///
|
||||
/// Suppresses the write-back effect during.
|
||||
pub fn set(&self, new_value: T)
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.write_back_effect.suppressed(|| self.signal.set(new_value));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user