Skip to content

Instantly share code, notes, and snippets.

@chrisza4
Created December 1, 2019 04:40
Show Gist options
  • Select an option

  • Save chrisza4/78b5cb77408e12a32b539f510f64f7e3 to your computer and use it in GitHub Desktop.

Select an option

Save chrisza4/78b5cb77408e12a32b539f510f64f7e3 to your computer and use it in GitHub Desktop.
export function deQueueWaitingMatters(
matterQueue: IWaitAnimatingMatter[],
now = new Date()
): IDeQueueWaitingMattersResult {
if (!isNeedAnimated(matterQueue, now)) {
return { newQueue: matterQueue }
}
const nextAnimationTime = moment(now)
.add(300, 'milliseconds')
.toDate()
const newQueue: IWaitAnimatingMatter[] = matterQueue
.slice(1)
.map<IWaitAnimatingMatter>(e => ({
expected_animated_time: nextAnimationTime,
matter: e.matter
}))
return {
newQueue,
matterToAnimated: matterQueue[0].matter
}
}
export function isNeedAnimated(
matterQueue: IWaitAnimatingMatter[],
now: Date = new Date()
) {
const animatingMatter = matterQueue[0]
if (!animatingMatter) {
return false
}
if (animatingMatter.expected_animated_time === null) {
return true
}
if (moment(now).isBefore(moment(animatingMatter.expected_animated_time))) {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment