diff --git a/docs/fetching/fetched.md b/docs/fetching/fetched.md index 62b9ed5..e7a647f 100644 --- a/docs/fetching/fetched.md +++ b/docs/fetching/fetched.md @@ -84,23 +84,23 @@ Getting the inner data or throw ```tsx function unwrap(fetched: Fetched): D { - return fetched.unwrap() + return fetched.getOrThrow() } ``` -Getting the inner data or undefined +Getting the inner data or nullable ```tsx function data(fetched: Fetched): D | undefined { - return fetched.ok().get() + return fetched.getOrNull() } ``` -Getting the inner error or undefined +Getting the inner error or nullable ```tsx function error(fetched: Fetched): F | undefined { - return fetched.err().get() + return fetched.getErrOrNull() } ``` @@ -108,7 +108,7 @@ Getting the inner data or error ```tsx function error(fetched: Fetched): D | F { - return fetched.inner + return fetched.getAny() } ``` @@ -116,7 +116,7 @@ Type-guarding if data ```tsx function f(fetched: Fetched): D | F { - if (fetched.isData()) + if (fetched.isOk()) return fetched.get() else return fetched.getErr() @@ -127,7 +127,7 @@ Type-guarding if error ```tsx function f(fetched: Fetched): D | F { - if (fetched.isFail()) + if (fetched.isErr()) return fetched.getErr() else return fetched.get() diff --git a/src/mods/core/core.ts b/src/mods/core/core.ts index 503f51a..b5b9f35 100644 --- a/src/mods/core/core.ts +++ b/src/mods/core/core.ts @@ -197,7 +197,7 @@ export class Core { const stored = await Result.runAndWrap(async () => { return settings.storage?.getOrThrow?.(cacheKey) - }).then(r => r?.ok().inner) + }).then(r => r?.getOrNull()) const unstored = await this.unstoreOrThrow(stored, settings) @@ -356,11 +356,11 @@ export class Core { const normalized = await this.#normalizeOrThrow(next.real?.current, settings) next = this.#mergeRealStateWithFetched(next, normalized) - if (next.real?.current.isData() && previous.real?.current.isData() && dataEqualser(next.real.current.inner, previous.real.current.inner)) - next = new RealState(new DataState(new Data(previous.real.current.inner, next.real.current))) + if (next.real?.current.isData() && previous.real?.current.isData() && dataEqualser(next.real.current.get(), previous.real.current.get())) + next = new RealState(new DataState(new Data(previous.real.current.get(), next.real.current))) - if (next.real?.current.isFail() && previous.real?.current.isFail() && errorEqualser(next.real.current.inner, previous.real.current.inner)) - next = new RealState(new FailState(new Fail(previous.real.current.inner, next.real.current), previous.real.data)) + if (next.real?.current.isFail() && previous.real?.current.isFail() && errorEqualser(next.real.current.getErr(), previous.real.current.getErr())) + next = new RealState(new FailState(new Fail(previous.real.current.getErr(), next.real.current), previous.real.data)) return await this.#reoptimizeOrThrow(cacheKey, next) }, settings) diff --git a/src/mods/queries/scroll/helper.ts b/src/mods/queries/scroll/helper.ts index bc36d3d..b368e5b 100644 --- a/src/mods/queries/scroll/helper.ts +++ b/src/mods/queries/scroll/helper.ts @@ -55,7 +55,7 @@ export namespace Scrollable { const prenormalized = await core.prenormalizeOrThrow(timed, settings) - if (prenormalized?.isData() && previous.real?.data && dataEqualser(prenormalized.inner, previous.real.data.inner)) + if (prenormalized?.isData() && previous.real?.data && dataEqualser(prenormalized.get(), previous.real.data.get())) return new Some(previous.real.data) return new Some(timed) @@ -78,7 +78,7 @@ export namespace Scrollable { settings: ScrollableFetcherfulQuerySettings ): Promise> { const previous = await core.getOrThrow(cacheKey, settings) - const previousPages = previous.real?.data?.inner ?? [] + const previousPages = previous.real?.data?.get() ?? [] const previousPage = Arrays.last(previousPages) const key = settings.scroller(previousPage) @@ -92,7 +92,7 @@ export namespace Scrollable { const timed = Fetched.from(fetched).setTimes(times) return await core.mutateOrThrow(cacheKey, async (previous) => { - const previousPages = previous.real?.data?.inner ?? [] + const previousPages = previous.real?.data?.get() ?? [] const paginated = timed.mapSync(data => [...previousPages, ...data]) return new Some(paginated) diff --git a/src/mods/queries/scroll/query.ts b/src/mods/queries/scroll/query.ts index 885799a..3b6e94c 100644 --- a/src/mods/queries/scroll/query.ts +++ b/src/mods/queries/scroll/query.ts @@ -167,7 +167,7 @@ export class ScrollableFetcherfulQuery { async peekOrNull(): Promise> { const { settings } = this const state = await this.state - const pages = state.real?.data?.inner + const pages = state.real?.data?.get() if (pages == null) return undefined @@ -223,7 +223,7 @@ export class ScrollableFetcherlessQuery { async peekOrNull(): Promise> { const { settings } = this const state = await this.state - const pages = state.real?.data?.inner + const pages = state.real?.data?.get() if (pages == null) return undefined diff --git a/src/mods/react/hooks/blocks/use-error.ts b/src/mods/react/hooks/blocks/use-error.ts index 1817fd4..ac12c5b 100644 --- a/src/mods/react/hooks/blocks/use-error.ts +++ b/src/mods/react/hooks/blocks/use-error.ts @@ -12,6 +12,6 @@ export function useError(query: ReactQuery, callback: (query: useEffect(() => { if (error == null) return - callback(query, error.inner) + callback(query, error.getErr()) }, [error]) } \ No newline at end of file diff --git a/src/mods/react/hooks/queries/scroll.ts b/src/mods/react/hooks/queries/scroll.ts index 7e7a2c0..1dade18 100644 --- a/src/mods/react/hooks/queries/scroll.ts +++ b/src/mods/react/hooks/queries/scroll.ts @@ -1,4 +1,4 @@ -import { None, Nullable, Option } from "@hazae41/option"; +import { None, Nullable } from "@hazae41/option"; import { Err, Fallback, Ok } from "@hazae41/result"; import { ScrollableQuery } from "index.js"; import { Arrays } from "libs/arrays/arrays.js"; @@ -233,7 +233,12 @@ export function useFetcherlessScrollableQuery( const fake = state?.fake const peekOrNull = useCallback(() => { - return Option.wrap(state?.real?.data?.inner).mapSync(pages => settings.scroller(Arrays.last(pages))).getOrNull() + const pages = state?.real?.data?.get() + + if (pages == null) + return undefined + + return settings.scroller(Arrays.last(pages)) }, [state?.real?.data, settings.scroller]) return { @@ -384,7 +389,7 @@ export function useFetcherfulScrollableQuery( const fake = state?.fake const peekOrNull = useCallback(() => { - const pages = state?.real?.data?.inner + const pages = state?.real?.data?.get() if (pages == null) return undefined