Skip to content

Commit

Permalink
Merge pull request #3662 from TrainLCD/fix/throttle
Browse files Browse the repository at this point in the history
結局負荷の原因になるので間引き処理復活
  • Loading branch information
TinyKitten authored Aug 10, 2024
2 parents 5b70ba7 + de6d7b5 commit 897d09e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/hooks/useLocationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ import { create } from 'zustand'
export const useLocationStore = create<LocationObject | null>(() => null)

export const setLocation = (location: LocationObject) =>
useLocationStore.setState(location, true)
useLocationStore.setState((state) => {
if (!state) {
return location
}

const { timestamp: inputTimestamp } = location
const { timestamp: stateTimestamp } = state

const diffInMs = inputTimestamp - stateTimestamp

if (diffInMs > 10 * 1000) {
return location
}

return state
})

0 comments on commit 897d09e

Please sign in to comment.