Skip to content

Commit

Permalink
improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
inker committed Sep 17, 2023
1 parent 68d7021 commit fa6ec03
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 49 deletions.
10 changes: 7 additions & 3 deletions src/pages/cl/gs/allPossibleGroupsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type GsWorkerData,
type GsWorkerPossibleGroupsResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -22,7 +22,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: GsWorkerData<Team>): GsWorkerPossibleGroupsResponseData => {
const func = (data: GsWorkerData<Team>): GsWorkerPossibleGroupsResponseData => {
const {
season,
pots,
Expand All @@ -36,4 +36,8 @@ exposeWorker((data: GsWorkerData<Team>): GsWorkerPossibleGroupsResponseData => {
return {
possibleGroups,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
10 changes: 7 additions & 3 deletions src/pages/cl/gs/firstPossibleGroupWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -22,7 +22,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const func = (data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const {
season,
pots,
Expand All @@ -36,4 +36,8 @@ exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
return {
pickedGroup,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
12 changes: 5 additions & 7 deletions src/pages/cl/gs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import {
} from 'lodash'

import type Team from 'model/team/GsTeam'
import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
type GsWorkerPossibleGroupsResponseData,
} from 'model/WorkerData'

import usePopup from 'store/usePopup'
import useDrawId from 'store/useDrawId'
Expand All @@ -37,6 +32,9 @@ import TeamBowl from 'ui/bowls/TeamBowl'
import GroupBowl from 'ui/bowls/GroupBowl'
import Announcement from 'ui/Announcement'

import { type Func as FirstPossibleGroupFunc } from './firstPossibleGroupWorker'
import { type Func as AllPossibleGroupsFunc } from './allPossibleGroupsWorker'

const createAllPossibleGroupsWorker = () =>
new Worker(new URL('./allPossibleGroupsWorker', import.meta.url))

Expand Down Expand Up @@ -111,9 +109,9 @@ function CLGS({
const [isXRay] = useXRay()

// eslint-disable-next-line max-len
const getFirstPossibleGroupResponse = useWorkerSendAndReceive<GsWorkerData<Team>, GsWorkerFirstPossibleResponseData>(createFirstPossibleGroupWorker)
const getFirstPossibleGroupResponse = useWorkerSendAndReceive(createFirstPossibleGroupWorker) as FirstPossibleGroupFunc
// eslint-disable-next-line max-len
const getAllPossibleGroupsResponse = useWorkerSendAndReceive<GsWorkerData<Team>, GsWorkerPossibleGroupsResponseData>(createAllPossibleGroupsWorker)
const getAllPossibleGroupsResponse = useWorkerSendAndReceive(createAllPossibleGroupsWorker) as AllPossibleGroupsFunc

const groupsContanerRef = useRef<HTMLElement>(null)

Expand Down
9 changes: 3 additions & 6 deletions src/pages/cl/ko/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
} from 'lodash'

import type Team from 'model/team/KnockoutTeam'
import {
type KoWorkerData,
type KoWorkerResponseData,
} from 'model/WorkerData'

import usePopup from 'store/usePopup'
import useDrawId from 'store/useDrawId'
Expand All @@ -34,6 +30,8 @@ import TeamBowl from 'ui/bowls/TeamBowl'
import Separator from 'ui/Separator'
import Announcement from 'ui/Announcement'

import { type Func } from './worker'

const createWorker = () =>
new Worker(new URL('./worker', import.meta.url))

Expand Down Expand Up @@ -85,8 +83,7 @@ function CLKO({
const [, setPopup] = usePopup()
const [isXRay] = useXRay()

// eslint-disable-next-line max-len
const getPossiblePairingsResponse = useWorkerSendAndReceive<KoWorkerData<Team>, KoWorkerResponseData>(createWorker)
const getPossiblePairingsResponse = useWorkerSendAndReceive(createWorker) as Func

const groupsContanerRef = useRef<HTMLElement>(null)

Expand Down
10 changes: 7 additions & 3 deletions src/pages/cl/ko/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type KoWorkerData,
type KoWorkerResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -21,7 +21,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: KoWorkerData<Team>): KoWorkerResponseData => {
const func = (data: KoWorkerData<Team>): KoWorkerResponseData => {
const {
season,
pots,
Expand All @@ -34,4 +34,8 @@ exposeWorker((data: KoWorkerData<Team>): KoWorkerResponseData => {
return {
possiblePairings,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
9 changes: 3 additions & 6 deletions src/pages/el/gs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
} from 'lodash'

import type Team from 'model/team/GsTeam'
import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
} from 'model/WorkerData'

import usePopup from 'store/usePopup'
import useDrawId from 'store/useDrawId'
Expand All @@ -34,6 +30,8 @@ import BowlsContainer from 'ui/BowlsContainer'
import TeamBowl from 'ui/bowls/TeamBowl'
import Announcement from 'ui/Announcement'

import { type Func } from './worker'

const createWorker = () =>
new Worker(new URL('./worker', import.meta.url))

Expand Down Expand Up @@ -96,8 +94,7 @@ function ELGS({
const [, setPopup] = usePopup()
const [isXRay] = useXRay()

// eslint-disable-next-line max-len
const getFirstPossibleGroupResponse = useWorkerSendAndReceive<GsWorkerData<Team>, GsWorkerFirstPossibleResponseData>(createWorker)
const getFirstPossibleGroupResponse = useWorkerSendAndReceive(createWorker) as Func

const groupsContanerRef = useRef<HTMLElement>(null)

Expand Down
10 changes: 7 additions & 3 deletions src/pages/el/gs/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -22,7 +22,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const func = (data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const {
season,
pots,
Expand All @@ -36,4 +36,8 @@ exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
return {
pickedGroup,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
9 changes: 3 additions & 6 deletions src/pages/el/ko/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
} from 'lodash'

import type Team from 'model/team/KnockoutTeam'
import {
type KoWorkerData,
type KoWorkerResponseData,
} from 'model/WorkerData'

import usePopup from 'store/usePopup'
import useDrawId from 'store/useDrawId'
Expand All @@ -35,6 +31,8 @@ import TeamBowl from 'ui/bowls/TeamBowl'
import Separator from 'ui/Separator'
import Announcement from 'ui/Announcement'

import { type Func } from './worker'

const createWorker = () =>
new Worker(new URL('./worker', import.meta.url))

Expand Down Expand Up @@ -87,8 +85,7 @@ function ELKO({
const [, setPopup] = usePopup()
const [isXRay] = useXRay()

// eslint-disable-next-line max-len
const getPossiblePairingsResponse = useWorkerSendAndReceive<KoWorkerData<Team>, KoWorkerResponseData>(createWorker)
const getPossiblePairingsResponse = useWorkerSendAndReceive(createWorker) as Func

const groupsContanerRef = useRef<HTMLElement>(null)

Expand Down
10 changes: 7 additions & 3 deletions src/pages/el/ko/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type KoWorkerData,
type KoWorkerResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -21,7 +21,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: KoWorkerData<Team>): KoWorkerResponseData => {
const func = (data: KoWorkerData<Team>): KoWorkerResponseData => {
const {
season,
pots,
Expand All @@ -34,4 +34,8 @@ exposeWorker((data: KoWorkerData<Team>): KoWorkerResponseData => {
return {
possiblePairings,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
9 changes: 3 additions & 6 deletions src/pages/wc/gs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import {
} from 'lodash'

import type Team from 'model/team/NationalTeam'
import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
} from 'model/WorkerData'

import usePopup from 'store/usePopup'
import useDrawId from 'store/useDrawId'
Expand All @@ -35,6 +31,8 @@ import BowlsContainer from 'ui/BowlsContainer'
import TeamBowl from 'ui/bowls/TeamBowl'
import Announcement from 'ui/Announcement'

import { type Func } from './worker'

const createWorker = () =>
new Worker(new URL('./worker', import.meta.url))

Expand Down Expand Up @@ -93,8 +91,7 @@ function WCGS({
const [, setPopup] = usePopup()
const [isXRay] = useXRay()

// eslint-disable-next-line max-len
const getFirstPossibleGroupResponse = useWorkerSendAndReceive<GsWorkerData<Team>, GsWorkerFirstPossibleResponseData>(createWorker)
const getFirstPossibleGroupResponse = useWorkerSendAndReceive(createWorker) as Func

const groupsContanerRef = useRef<HTMLElement>(null)

Expand Down
10 changes: 7 additions & 3 deletions src/pages/wc/gs/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type GsWorkerData,
type GsWorkerFirstPossibleResponseData,
} from 'model/WorkerData'
import exposeWorker from 'utils/worker/expose'
import exposeWorker, { type ExposedFuncType } from 'utils/worker/expose'

type GetPredicateParams = Parameters<typeof getPredicate>

Expand All @@ -25,7 +25,7 @@ const eqFunc = (newArgs: GetPredicateParams, oldArgs: GetPredicateParams) =>

const getPredicateMemoized = memoizeOne(getPredicate, eqFunc)

exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const func = (data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
const {
season,
pots,
Expand All @@ -44,4 +44,8 @@ exposeWorker((data: GsWorkerData<Team>): GsWorkerFirstPossibleResponseData => {
return {
pickedGroup,
}
})
}

export type Func = ExposedFuncType<typeof func>

exposeWorker(func)
3 changes: 3 additions & 0 deletions src/utils/worker/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ export default <F extends (arg: any) => any>(func: F) => {
})
})
}

export type ExposedFuncType<F extends (...args: readonly any[]) => any> =
(...args: Parameters<F>) => Promise<ReturnType<F>>

0 comments on commit fa6ec03

Please sign in to comment.