-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from appwrite/feat/in-progress-execution-timer
Feat: function execution timer
- Loading branch information
Showing
4 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { calculateTime } from '$lib/helpers/timeConversion'; | ||
import type { Action } from 'svelte/action'; | ||
|
||
type Props = { | ||
start?: string; | ||
enabled?: boolean; | ||
}; | ||
|
||
const defaultProps: Props = { | ||
enabled: true | ||
}; | ||
|
||
export const timer: Action<HTMLElement, Props> = (node, props) => { | ||
let startDate: Date; | ||
let frame: number; | ||
|
||
function init(props: Props) { | ||
const { start, enabled } = { ...defaultProps, ...props }; | ||
startDate = start ? new Date(start) : new Date(); | ||
frame = enabled ? window.requestAnimationFrame(step) : null; | ||
} | ||
|
||
function step() { | ||
const diffInSeconds = Math.floor((new Date().getTime() - startDate.getTime()) / 1000); | ||
node.textContent = calculateTime(diffInSeconds); | ||
frame = window.requestAnimationFrame(step); | ||
} | ||
|
||
init(props); | ||
|
||
return { | ||
update(props) { | ||
window.cancelAnimationFrame(frame); | ||
init(props); | ||
}, | ||
destroy() { | ||
window.cancelAnimationFrame(frame); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ccf53ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console – ./
console-appwrite.vercel.app
svelte-console.vercel.app
console-git-main-appwrite.vercel.app
demo.appwriters.com
brand-new-console.torsten.appwrite.org