Skip to content

Commit

Permalink
fix useFramerate
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Nov 8, 2024
1 parent cca7194 commit 65b5ae1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .husky/_/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ call_lefthook()
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
Expand Down
3 changes: 0 additions & 3 deletions .husky/_/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ call_lefthook()
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
Expand Down
3 changes: 0 additions & 3 deletions .husky/_/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ call_lefthook()
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
Expand Down
10 changes: 6 additions & 4 deletions hooks/use-framerate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useFrame } from '@darkroom.engineering/hamo'
import { useRef } from 'react'

export function useFramerate(fps, callback) {
export function useFramerate(fps, callback, priority = 0) {
const timeRef = useRef(0)

useFrame((time, delaTime) => {
timeRef.current += delaTime

if (timeRef.current > 1000 / (typeof fps === 'function' ? fps() : fps)) {
timeRef.current = 0
const executionTime = 1000 / (typeof fps === 'function' ? fps() : fps)

if (timeRef.current >= executionTime) {
timeRef.current = timeRef.current % executionTime
callback?.(time, delaTime)
}
})
}, priority)
}

1 comment on commit 65b5ae1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚡️ Lighthouse report for the changes in this commit:

🟢 Performance: 100
🟢 Accessibility: 90
🟢 Best practices: 96
🟠 SEO: 63

Lighthouse ran on https://satus-89fjur2tc-darkroom-engineering.vercel.app/

Please sign in to comment.