Skip to content

Commit

Permalink
Remove dependency on chrono (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 authored Sep 6, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9346692 commit c1787f5
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion packages/sycamore/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ version = "0.5.2"

[dependencies]
ahash = "0.7.4"
chrono = { version = "0.4.19", features = ["wasmbind"] }
html-escape = { version = "0.2.9", optional = true }
indexmap = { version = "1.7.0", features = ["std"] }
js-sys = "0.3.53"
20 changes: 9 additions & 11 deletions packages/sycamore/src/motion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;

use chrono::{prelude::*, Duration};
use js_sys::Date;

use crate::reactive::Signal;
use crate::utils::{loop_raf, Task};
@@ -67,7 +67,7 @@ pub struct Tweened<T: Lerp + Clone + 'static>(Rc<RefCell<TweenedInner<T>>>);
struct TweenedInner<T: Lerp + Clone + 'static> {
signal: Signal<T>,
current_task: Option<Task>,
transition_duration: Duration,
transition_duration_ms: f32,
easing_fn: Rc<dyn Fn(f32) -> f32>,
}

@@ -81,8 +81,7 @@ impl<T: Lerp + Clone + 'static> Tweened<T> {
Self(Rc::new(RefCell::new(TweenedInner {
signal: Signal::new(initial),
current_task: None,
transition_duration: Duration::from_std(transition_duration)
.expect("transition_duration is greater than the maximum value"),
transition_duration_ms: transition_duration.as_millis() as f32,
easing_fn: Rc::new(easing_fn),
})))
}
@@ -99,18 +98,17 @@ impl<T: Lerp + Clone + 'static> Tweened<T> {
let start = self.signal().get_untracked().as_ref().clone();
let easing_fn = Rc::clone(&self.0.borrow().easing_fn);

let start_time = Utc::now();
let start_time = Date::now();
let signal = self.0.borrow().signal.clone();
let transition_duration = self.0.borrow().transition_duration;
let transition_duration_ms = self.0.borrow().transition_duration_ms;

let task = Task::new(move || {
let now = Utc::now();
let now = Date::now();

let since_start = now - start_time;
let scalar = since_start.num_milliseconds() as f32
/ transition_duration.num_milliseconds() as f32;
let scalar = since_start as f32 / transition_duration_ms;

if now < start_time + transition_duration {
if now < start_time + transition_duration_ms as f64 {
signal.set(start.lerp(&new_value, easing_fn(scalar)));
true
} else {
@@ -155,7 +153,7 @@ impl<T: Lerp + Clone + 'static> Clone for TweenedInner<T> {
Self {
signal: self.signal.clone(),
current_task: self.current_task.clone(),
transition_duration: self.transition_duration,
transition_duration_ms: self.transition_duration_ms,
easing_fn: Rc::clone(&self.easing_fn),
}
}

0 comments on commit c1787f5

Please sign in to comment.