Skip to content

Commit

Permalink
chore: JSDoc overload example
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Nov 29, 2022
1 parent 268e4f7 commit 70fad5f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/renderer/hooks/useMapServerQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ import { useQuery } from '@tanstack/react-query'
// global port number
const MAP_SERVER_URL = 'http://127.0.0.1:' + window.mapServerPort

/** @typedef {import('@mapeo/map-server/dist/lib/stylejson').StyleJSON } StyleJSON */
/** @typedef {import('@mapeo/map-server/dist/lib/tilejson').TileJSON } TileJSON */
/** @typedef {ReturnType<import('@mapeo/map-server/dist/api/styles').StylesApi["listStyles"]>} MapServerStyleInfo */
/**
* @param {'/styles' | `/styles/${string}` | '/tilesets' | `/tilesets/${string}`} resourcePath URL path to resource on Map Server (needs to start with `/`)
* @template TData
* @typedef {import('@tanstack/react-query').UseQueryResult<TData>} UseQueryResult<TData>
*/

/**
* @type {{
* (resourcePath: '/styles') => UseQueryResult<MapServerStyleInfo>
* (resourcePath: `/styles/${string}`) => UseQueryResult<StyleJSON>
* }}
*/
export function useMapServerQuery (resourcePath) {
return useQuery({
queryKey: [resourcePath],
queryFn: () => ky.get(MAP_SERVER_URL + resourcePath).json()
})
}

/**
* @type {import('@tanstack/react-query').UseQueryResult<ReturnType<import('@mapeo/map-server/dist/api/styles').StylesApi["listStyles"]>>}
*/
const { data } = useMapServerQuery('/styles')
;(async () => {
const { data } = await useMapServerQuery('/styles')
})()

0 comments on commit 70fad5f

Please sign in to comment.