Skip to content

Commit 745f21e

Browse files
DOMA-3719 Updated docstrings and other refactoring
1 parent 455a90e commit 745f21e

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

apps/condo/domains/common/hooks/useCurrentBuild.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ const {
66
publicRuntimeConfig: { serverUrl },
77
} = getConfig()
88

9-
const REQUEST_KEY = '/api/version'
10-
const API_ROUTE = `${serverUrl}${REQUEST_KEY}`
9+
const REQUEST_CACHE_KEY = '/api/version'
10+
const FETCH_ROUTE = `${serverUrl}/api/version`
1111

1212
async function fetchBuildInfo () {
13-
const response = await fetch(API_ROUTE)
13+
const response = await fetch(FETCH_ROUTE)
1414
return await response.json()
1515
}
1616

17+
/**
18+
* Fetch data about current build from a remote url using useSWR under the hood
19+
* Which is similar to useQuery from "apollo-client"
20+
* It has cache-validating mechanism:
21+
* 1. Return value from cache by specified key
22+
* 2. Fetch data from remote url and compare with cache value
23+
* 3. Update return value if needed
24+
*/
1725
export function useCurrentBuild (): string {
18-
const { data } = useSWR(REQUEST_KEY, fetchBuildInfo)
26+
const { data } = useSWR(REQUEST_CACHE_KEY, fetchBuildInfo)
1927

2028
return get(data, 'build', null)
2129
}

apps/condo/domains/common/hooks/useHotCodeReload.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { Button } from '@condo/domains/common/components/Button'
66
import { useCurrentBuild } from './useCurrentBuild'
77
import { usePrevious } from './usePrevious'
88

9-
10-
9+
/**
10+
* Periodically fetch information about build and compare it with previous value
11+
* If a change is found, a notification is shown to the user asking them to reload the tab
12+
*/
1113
export function useHotCodeReload (): void {
1214
const intl = useIntl()
1315
const NotificationTitle = intl.formatMessage({ id: 'HotCodeReload.title' })

apps/condo/domains/common/hooks/usePrevious.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { useEffect, useRef } from 'react'
22

33
/**
4-
* Monitoring some variable value
5-
* After it's change useEffect will update ref
6-
* But before that will be returned previous value
4+
* Monitor some `variable` value
5+
* Until `variable` is changed its previous value would be returned
6+
* Changing the value of a variable will trigger an async ref change via useEffect
7+
* At this point, the return value will still be the same
8+
* This will catch the update state where value !== return value
9+
* After useEffect has finished, the input and output value will be the same again
710
* @param value to monitor
811
*/
912
export function usePrevious<T> (value: T): T {

0 commit comments

Comments
 (0)