diff --git a/src/animation.rs b/src/animation.rs index 67c2dcf..1442ef8 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -60,17 +60,20 @@ struct TimestampsGlobal { value: Arc>>, } +#[derive(Debug)] enum TimestampsEnum { First, Changed, NotChanged, } +#[derive(Debug)] struct TimestampsState { state: TimestampsEnum, waker: Option, } +#[derive(Debug)] pub struct Timestamps { state: Arc>, // TODO verify that there aren't any Arc cycles @@ -189,6 +192,7 @@ impl AnimatedSignalVec for S { } +#[derive(Debug)] pub struct AnimatedMapBroadcaster(MutableAnimation); impl AnimatedMapBroadcaster { @@ -200,12 +204,14 @@ impl AnimatedMapBroadcaster { } +#[derive(Debug)] struct AnimatedMapState { animation: MutableAnimation, removing: Option>, } // TODO move this into signals crate and also generalize it to work with any future, not just animations +#[derive(Debug)] pub struct AnimatedMap { duration: f64, animations: Vec, @@ -517,19 +523,27 @@ impl MutableTimestamps where F: FnMut(f64) { }*/ +pub fn timestamps_difference() -> impl Signal> { + let mut starting_time = None; + + timestamps().map(move |current_time| { + current_time.map(|current_time| { + let starting_time = *starting_time.get_or_insert(current_time); + current_time - starting_time + }) + }) +} + + pub struct OnTimestampDiff(DiscardOnDrop); impl OnTimestampDiff { pub fn new(mut callback: F) -> Self where F: FnMut(f64) + 'static { - let mut starting_time = None; - OnTimestampDiff(spawn_future( - timestamps() - .for_each(move |current_time| { - if let Some(current_time) = current_time { - let starting_time = *starting_time.get_or_insert(current_time); - - callback(current_time - starting_time); + timestamps_difference() + .for_each(move |diff| { + if let Some(diff) = diff { + callback(diff); } ready(()) @@ -546,6 +560,7 @@ impl fmt::Debug for OnTimestampDiff { } +#[derive(Debug)] pub struct MutableAnimationSignal(MutableSignal); impl Signal for MutableAnimationSignal { @@ -570,6 +585,8 @@ struct MutableAnimationInner { value: Mutable, } +// TODO deref to ReadOnlyMutable ? +// TODO provide read_only() method ? pub struct MutableAnimation { inner: Arc, }