Skip to content

Commit

Permalink
refactor: inject the devtools middleware as a built-in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jun 26, 2022
1 parent f05d933 commit ef610a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions _internal/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type {
} from '../types'
import { stableHash } from './hash'
import { initCache } from './cache'
import { preset as webPreset } from './web-preset'
import { preset as devtoolsPreset } from './devtools'
import { preset } from './web-preset'
import { slowConnection } from './env'
import { isUndefined, noop, mergeObjects } from './helper'

Expand Down Expand Up @@ -74,6 +73,6 @@ export const defaultConfig: FullConfiguration = mergeObjects(
mutate,
fallback: {}
},
// use web and devtools preset by default
mergeObjects(webPreset, devtoolsPreset)
// use web preset by default
preset
)
8 changes: 5 additions & 3 deletions _internal/utils/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import { isWindowDefined } from './helper'

export const preset = {
export const middlewares =
// @ts-expect-error
use: isWindowDefined ? window.__SWR_DEVTOOLS_USE__ : []
}
isWindowDefined && window.__SWR_DEVTOOLS_USE__
? // @ts-expect-error
window.__SWR_DEVTOOLS_USE__
: []

export const setupDevTools = () => {
if (isWindowDefined) {
Expand Down
3 changes: 2 additions & 1 deletion _internal/utils/middleware-preset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { middlewares as devtoolMiddlewares } from './devtools'
import { middleware as preload } from './preload'

export const BUILT_IN_MIDDLEWARE = [preload]
export const BUILT_IN_MIDDLEWARE = devtoolMiddlewares.concat(preload)

0 comments on commit ef610a4

Please sign in to comment.