Skip to content

Commit

Permalink
feat:refactor(ts/components/follower): only call onUpdate if not `u…
Browse files Browse the repository at this point in the history
…ndefined`
  • Loading branch information
firestack committed Oct 23, 2023
1 parent ad4759a commit e8a1c23
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions assets/src/components/map/follower.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type UpdateMapFromPointsFn = (map: LeafletMap, points: LatLng[]) => void

export interface FollowerProps {
positions: LatLng[]
onUpdate: UpdateMapFromPointsFn
onUpdate?: UpdateMapFromPointsFn
}

export const Follower = ({
Expand All @@ -48,7 +48,7 @@ export const Follower = ({
if (isAnimatingFollowUpdate !== undefined) {
isAnimatingFollowUpdate.current = true
}
onUpdate(map, currentLatLngs)
onUpdate?.(map, currentLatLngs)
}
}, [map, shouldFollow, isAnimatingFollowUpdate, currentLatLngs, onUpdate])

Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/mapPage/mapDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const SelectedVehicleDataLayers = ({
/>
<InterruptibleFollower
// Do nothing if we don't have a vehicle position yet
onUpdate={position.length === 0 ? () => {} : onUpdate}
onUpdate={position.length > 0 ? onUpdate : undefined}
positions={position}
{...followerState}
setShouldFollow={(...args) => {
Expand Down

0 comments on commit e8a1c23

Please sign in to comment.