Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorganize entries #3048

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"fetch"
],
"packageManager": "[email protected]",
"main": "./dist/core/index.js",
"module": "./dist/core/index.mjs",
"types": "./dist/core/index.d.ts",
"main": "./dist/index/index.js",
"module": "./dist/index/index.mjs",
"types": "./dist/index/index.d.ts",
"sideEffects": false,
"exports": {
"./package.json": "./package.json",
".": {
"react-server": "./dist/core/react-server.mjs",
"react-server": "./dist/index/react-server.mjs",
"import": {
"types": "./dist/core/index.d.mts",
"default": "./dist/core/index.mjs"
"types": "./dist/index/index.d.mts",
"default": "./dist/index/index.mjs"
},
"require": {
"types": "./dist/core/index.d.ts",
"default": "./dist/core/index.js"
"types": "./dist/index/index.d.ts",
"default": "./dist/index/index.js"
}
},
"./infinite": {
Expand Down
30 changes: 0 additions & 30 deletions src/core/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/immutable/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Middleware } from '../core'
import useSWR from '../core'
import type { Middleware } from '../index'
import useSWR from '../index'
import { withMiddleware } from '../_internal'

export const immutable: Middleware = useSWRNext => (key, fetcher, config) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index/index.react-server.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { unstable_serialize } from '../core/serialize'
export { unstable_serialize } from './serialize'
export { SWRConfig } from './config'
32 changes: 30 additions & 2 deletions src/index/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
export * from '../core'
export { default } from '../core'
// useSWR
import useSWR from './use-swr'
export default useSWR
// Core APIs
export { SWRConfig } from './use-swr'
export { unstable_serialize } from './serialize'
export { useSWRConfig } from '../_internal'
export { mutate } from '../_internal'
export { preload } from '../_internal'

// Types
export type {
SWRConfiguration,
Revalidator,
RevalidatorOptions,
Key,
KeyLoader,
KeyedMutator,
SWRHook,
SWRResponse,
Cache,
BareFetcher,
Fetcher,
MutatorCallback,
MutatorOptions,
Middleware,
Arguments,
State,
ScopedMutator
} from '../_internal'
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/use-swr.ts → src/index/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const useSWRHandler = <Data = any, Error = any>(
const cachedData = cached.data

const data = isUndefined(cachedData)
? (fallback && isPromiseLike(fallback))
? fallback && isPromiseLike(fallback)
? use(fallback)
: fallback
: cachedData
Expand Down
13 changes: 2 additions & 11 deletions src/infinite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// hook where `key` and return type are not like the normal `useSWR` types.

import { useRef, useCallback } from 'react'
import type { SWRConfig } from '../core'
import useSWR from '../core'
import type { SWRConfig } from '../index'
import useSWR from '../index'
import {
isUndefined,
isFunction,
Expand Down Expand Up @@ -37,19 +37,10 @@ import type {
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'
import { getFirstPageKey } from './serialize'

// const INFINITE_PREFIX = '$inf$'
const EMPTY_PROMISE = Promise.resolve() as Promise<undefined>

// const getFirstPageKey = (getKey: SWRInfiniteKeyLoader) => {
// return serialize(getKey ? getKey(0, null) : null)[0]
// }

export { unstable_serialize } from './serialize'

// export const unstable_serialize = (getKey: SWRInfiniteKeyLoader) => {
// return INFINITE_PREFIX + getFirstPageKey(getKey)
// }

export const infinite = (<Data, Error>(useSWRNext: SWRHook) =>
(
getKey: SWRInfiniteKeyLoader,
Expand Down
2 changes: 1 addition & 1 deletion src/mutation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useRef } from 'react'
import useSWR, { useSWRConfig } from '../core'
import useSWR, { useSWRConfig } from '../index'
import type { Middleware, Key } from '../_internal'
import { useStateWithDeps, startTransition } from './state'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/mutation/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SWRResponse, Key, Arguments } from '../core'
import type { SWRResponse, Key, Arguments } from '../index'

type FetcherResponse<Data> = Data | Promise<Data>

Expand Down
4 changes: 2 additions & 2 deletions src/subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type {
Middleware,
SWRConfiguration,
SWRConfig
} from '../core'
} from '../index'
import type {
SWRSubscriptionOptions,
SWRSubscription,
SWRSubscriptionResponse,
SWRSubscriptionHook
} from './types'
import useSWR from '../core'
import useSWR from '../index'
import {
withMiddleware,
serialize,
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Key, SWRConfiguration, MutatorCallback } from '../core'
import type { Key, SWRConfiguration, MutatorCallback } from '../index'

export type SWRSubscriptionOptions<Data = any, Error = any> = {
next: (err?: Error | null, data?: Data | MutatorCallback<Data>) => void
Expand Down
Loading