-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: call bootstrap before running the app
- Loading branch information
Showing
15 changed files
with
171 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
apps/hub/src/domains/project/components/servers/server-datacenter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Adapted from: https://github.com/streamich/react-use/blob/e1d0cd9f7fb2a124a9d46879489abfefdf48d836/src/misc/types.ts | ||
|
||
export type PromiseType<P extends Promise<unknown>> = P extends Promise<infer T> | ||
? T | ||
: never; | ||
// biome-ignore lint/suspicious/noExplicitAny: this is a type that is used to represent a function that returns a promise | ||
export type FunctionReturningPromise = (...args: any[]) => Promise<any>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Adapted from https://github.com/streamich/react-use/blob/e1d0cd9f7fb2a124a9d46879489abfefdf48d836/src/useAsyncFn.ts | ||
import { type DependencyList, useCallback, useRef, useState } from "react"; | ||
import type { FunctionReturningPromise, PromiseType } from "./types"; | ||
import useMountedState from "./use-mounted-state"; | ||
|
||
export type AsyncState<T> = | ||
| { | ||
loading: boolean; | ||
error?: undefined; | ||
value?: undefined; | ||
} | ||
| { | ||
loading: true; | ||
error?: Error | undefined; | ||
value?: T; | ||
} | ||
| { | ||
loading: false; | ||
error: Error; | ||
value?: undefined; | ||
} | ||
| { | ||
loading: false; | ||
error?: undefined; | ||
value: T; | ||
}; | ||
|
||
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = | ||
AsyncState<PromiseType<ReturnType<T>>>; | ||
|
||
export type AsyncFnReturn< | ||
T extends FunctionReturningPromise = FunctionReturningPromise, | ||
> = [StateFromFunctionReturningPromise<T>, T]; | ||
|
||
export function useAsyncFn<T extends FunctionReturningPromise>( | ||
fn: T, | ||
deps: DependencyList = [], | ||
initialState: StateFromFunctionReturningPromise<T> = { loading: false }, | ||
): AsyncFnReturn<T> { | ||
const lastCallId = useRef(0); | ||
const isMounted = useMountedState(); | ||
const [state, set] = | ||
useState<StateFromFunctionReturningPromise<T>>(initialState); | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: we don't want to re-run this effect when `fn` changes | ||
const callback = useCallback((...args: Parameters<T>): ReturnType<T> => { | ||
const callId = ++lastCallId.current; | ||
|
||
if (!state.loading) { | ||
set((prevState) => ({ ...prevState, loading: true })); | ||
} | ||
|
||
return fn(...args).then( | ||
(value) => { | ||
isMounted() && | ||
callId === lastCallId.current && | ||
set({ value, loading: false }); | ||
|
||
return value; | ||
}, | ||
(error) => { | ||
isMounted() && | ||
callId === lastCallId.current && | ||
set({ error, loading: false }); | ||
|
||
return error; | ||
}, | ||
) as ReturnType<T>; | ||
}, deps); | ||
|
||
return [state, callback as unknown as T]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Adapted from: https://github.com/streamich/react-use/blob/e1d0cd9f7fb2a124a9d46879489abfefdf48d836/src/useAsync.ts | ||
import { type DependencyList, useEffect } from "react"; | ||
import type { FunctionReturningPromise } from "./types"; | ||
import { useAsyncFn } from "./use-async-fn"; | ||
|
||
export { type AsyncState, type AsyncFnReturn } from "./use-async-fn"; | ||
Check failure on line 6 in apps/hub/src/hooks/use-async.ts GitHub Actions / qualitylint/style/useExportType
|
||
|
||
export function useAsync<T extends FunctionReturningPromise>( | ||
fn: T, | ||
deps: DependencyList = [], | ||
) { | ||
const [state, callback] = useAsyncFn(fn, deps, { | ||
loading: true, | ||
}); | ||
|
||
useEffect(() => { | ||
callback(); | ||
}, [callback]); | ||
|
||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Adapted from: https://github.com/streamich/react-use/blob/e1d0cd9f7fb2a124a9d46879489abfefdf48d836/src/useMountedState.ts | ||
import { useCallback, useEffect, useRef } from "react"; | ||
|
||
export default function useMountedState(): () => boolean { | ||
const mountedRef = useRef<boolean>(false); | ||
const get = useCallback(() => mountedRef.current, []); | ||
|
||
useEffect(() => { | ||
mountedRef.current = true; | ||
|
||
return () => { | ||
mountedRef.current = false; | ||
}; | ||
}, []); | ||
|
||
return get; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters