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: Code refactoring #1533

Merged
merged 3 commits into from
Oct 6, 2021
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
2 changes: 1 addition & 1 deletion src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useSWRHandler = <Data = any, Error = any>(
// - `revalidateIfStale` is enabled but `data` is not defined.
const shouldRevalidateOnMount = () => {
if (!isUndefined(revalidateOnMount)) return revalidateOnMount
if (configRef.current.isPaused()) return false
if (getConfig().isPaused()) return false

return suspense
? !initialMountedRef.current && !isUndefined(data)
Expand Down
11 changes: 8 additions & 3 deletions src/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// `undefined` can possibly be replaced by something else.
export const UNDEFINED: undefined = ({} as any)[0]
export const noop = () => {}

// Using noop() as the undefined value as undefined can possibly be replaced
// by something else. Prettier ignore and extra parentheses are necessary here
// to ensure that tsc doesn't remove the __NOINLINE__ comment.
// prettier-ignore
export const UNDEFINED: undefined = (/*#__NOINLINE__*/ noop()) as undefined

export const isUndefined = (v: any): v is undefined => v === UNDEFINED
export const isFunction = (v: any): v is Function => typeof v == 'function'
export const noop = () => {}
export const mergeObjects = (a: any, b: any) => Object.assign({}, a, b)

const STR_UNDEFINED = 'undefined'
Expand Down