Skip to content

Commit 5e2f2c2

Browse files
authored
chore: update tooling (#3086)
* chore: update caniuselite * chore: remove const-enum babel plugin because we don't use const-enums anymore * chore: require ts 4.1 * chore: update rollup and plugins * chore: update typescript and ts-eslint * refactor: remove notifiable base class this abstraction costs more than the simple duplication, and we also have other notify functions which were not unified
1 parent 3722b6b commit 5e2f2c2

15 files changed

Lines changed: 1486 additions & 1087 deletions

.babelrc.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ module.exports = {
1616
'@babel/react',
1717
],
1818
plugins: [
19-
[
20-
'const-enum',
21-
{
22-
transform: 'constObject',
23-
},
24-
],
2519
'babel-plugin-transform-async-to-promises',
2620
cjs && ['@babel/transform-modules-commonjs', { loose }],
2721
[

.browserslistrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ Chrome >= 73
44
ChromeAndroid >= 75
55
Firefox >= 67
66
Edge >= 17
7-
IE 11
87
Safari >= 12.1
9-
iOS >= 11.3
8+
iOS >= 11.3

docs/src/pages/guides/migrating-to-react-query-4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ The methods `cancelMutatations` and `executeMutation` were undocumented and unus
243243
- }
244244
```
245245

246+
### TypeScript
247+
248+
Types now require using TypeScript v4.1 or greater
249+
246250
## New Features 🚀
247251

248252
### Proper offline support

docs/src/pages/typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ React Query is now written in **TypeScript** to make sure the library and your p
77

88
Things to keep in mind:
99

10-
- Types currently require using TypeScript v3.8 or greater
10+
- Types currently require using TypeScript v4.1 or greater
1111
- for [useQueries](../reference/useQueries), TypeScript v4.1 or greater is required to get the correct return type for each individual query (below v4.1 will mean the type of each returned `data` property is left as `unknown`)
1212
- Changes to types in this repository are considered **non-breaking** and are usually released as **patch** semver changes (otherwise every type enhancement would be a major version!).
1313
- It is **highly recommended that you lock your react-query package version to a specific patch release and upgrade with the expectation that types may be fixed or upgraded between any release**

package.json

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,24 @@
8080
"optional": true
8181
}
8282
},
83-
"typesVersions": {
84-
"<4.1": {
85-
"types/*": [
86-
"types/ts3.8/*"
87-
]
88-
}
89-
},
9083
"devDependencies": {
9184
"@babel/cli": "^7.11.6",
9285
"@babel/core": "^7.11.6",
9386
"@babel/plugin-transform-runtime": "^7.11.5",
9487
"@babel/preset-env": "^7.11.5",
9588
"@babel/preset-react": "^7.10.4",
9689
"@babel/preset-typescript": "^7.10.4",
97-
"@rollup/plugin-replace": "^2.3.3",
98-
"@svgr/rollup": "^5.4.0",
90+
"@rollup/plugin-replace": "^3.0.0",
91+
"@svgr/rollup": "^6.1.1",
9992
"@testing-library/react": "^10.4.7",
10093
"@testing-library/jest-dom": "^5.14.1",
10194
"@types/jest": "^26.0.4",
10295
"@types/react": "^16.9.41",
10396
"@types/react-dom": "^16.9.8",
104-
"@typescript-eslint/eslint-plugin": "^4.8.1",
105-
"@typescript-eslint/parser": "^4.8.1",
97+
"@typescript-eslint/eslint-plugin": "^5.6.0",
98+
"@typescript-eslint/parser": "^5.6.0",
10699
"babel-eslint": "^10.1.0",
107100
"babel-jest": "^26.0.1",
108-
"babel-plugin-const-enum": "^1.0.1",
109101
"babel-plugin-transform-async-to-promises": "^0.8.15",
110102
"bundlewatch": "^0.3.2",
111103
"cross-env": "^7.0.2",
@@ -121,7 +113,7 @@
121113
"eslint-plugin-prettier": "^3.1.3",
122114
"eslint-plugin-promise": "^4.2.1",
123115
"eslint-plugin-react": "7.20.0",
124-
"eslint-plugin-react-hooks": "4.2.0",
116+
"eslint-plugin-react-hooks": "^4.3.0",
125117
"eslint-plugin-standard": "^4.0.1",
126118
"is-ci-cli": "^2.1.1",
127119
"jest": "^26.0.1",
@@ -131,18 +123,18 @@
131123
"react-error-boundary": "^2.2.2",
132124
"replace": "^1.2.0",
133125
"rimraf": "^3.0.2",
134-
"rollup": "^2.16.1",
126+
"rollup": "^2.61.1",
135127
"rollup-plugin-babel": "^4.4.0",
136128
"rollup-plugin-commonjs": "^10.1.0",
137-
"rollup-plugin-jscc": "^1.0.0",
129+
"rollup-plugin-jscc": "^2.0.0",
138130
"rollup-plugin-node-resolve": "^5.2.0",
139-
"rollup-plugin-peer-deps-external": "^2.2.2",
140-
"rollup-plugin-prettier": "^2.1.0",
131+
"rollup-plugin-peer-deps-external": "^2.2.4",
132+
"rollup-plugin-prettier": "^2.2.0",
141133
"rollup-plugin-size": "^0.2.2",
142-
"rollup-plugin-terser": "^6.1.0",
143-
"rollup-plugin-visualizer": "^4.0.4",
134+
"rollup-plugin-terser": "^7.0.2",
135+
"rollup-plugin-visualizer": "^5.5.2",
144136
"type-fest": "^0.21.0",
145-
"typescript": "^4.1.2"
137+
"typescript": "4.5.3"
146138
},
147139
"resolutions": {
148140
"@types/react": "^16.9.41",

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default inputSrcs
7979
replace({
8080
'process.env.NODE_ENV': `"production"`,
8181
delimiters: ['', ''],
82+
preventAssignment: true,
8283
}),
8384
resolve(resolveConfig),
8485
babel(babelConfig),

src/core/mutationCache.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { QueryClient } from './queryClient'
44
import { notifyManager } from './notifyManager'
55
import { Action, Mutation, MutationState } from './mutation'
66
import { matchMutation, MutationFilters, noop } from './utils'
7-
import { Notifiable } from './notifiable'
7+
import { Subscribable } from './subscribable'
88

99
// TYPES
1010

@@ -61,9 +61,11 @@ type MutationCacheNotifyEvent =
6161
| NotifyEventMutationObserverRemoved
6262
| NotifyEventMutationUpdated
6363

64+
type MutationCacheListener = (event: MutationCacheNotifyEvent) => void
65+
6466
// CLASS
6567

66-
export class MutationCache extends Notifiable<MutationCacheNotifyEvent> {
68+
export class MutationCache extends Subscribable<MutationCacheListener> {
6769
config: MutationCacheConfig
6870

6971
private mutations: Mutation<any, any, any, any>[]
@@ -134,6 +136,14 @@ export class MutationCache extends Notifiable<MutationCacheNotifyEvent> {
134136
return this.mutations.filter(mutation => matchMutation(filters, mutation))
135137
}
136138

139+
notify(event: MutationCacheNotifyEvent) {
140+
notifyManager.batch(() => {
141+
this.listeners.forEach(listener => {
142+
listener(event)
143+
})
144+
})
145+
}
146+
137147
onFocus(): void {
138148
this.resumePausedMutations()
139149
}

src/core/notifiable.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/core/queryCache.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Action, Query, QueryState } from './query'
88
import type { QueryKey, QueryOptions } from './types'
99
import { notifyManager } from './notifyManager'
1010
import type { QueryClient } from './queryClient'
11-
import { Notifiable } from './notifiable'
11+
import { Subscribable } from './subscribable'
1212
import { QueryObserver } from './queryObserver'
1313

1414
// TYPES
@@ -63,9 +63,11 @@ type QueryCacheNotifyEvent =
6363
| NotifyEventQueryObserverRemoved
6464
| NotifyEventQueryObserverResultsUpdated
6565

66+
type QueryCacheListener = (event: QueryCacheNotifyEvent) => void
67+
6668
// CLASS
6769

68-
export class QueryCache extends Notifiable<QueryCacheNotifyEvent> {
70+
export class QueryCache extends Subscribable<QueryCacheListener> {
6971
config: QueryCacheConfig
7072

7173
private queries: Query<any, any, any, any>[]
@@ -177,6 +179,14 @@ export class QueryCache extends Notifiable<QueryCacheNotifyEvent> {
177179
: this.queries
178180
}
179181

182+
notify(event: QueryCacheNotifyEvent) {
183+
notifyManager.batch(() => {
184+
this.listeners.forEach(listener => {
185+
listener(event)
186+
})
187+
})
188+
}
189+
180190
onFocus(): void {
181191
notifyManager.batch(() => {
182192
this.queries.forEach(query => {

src/core/queryObserver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class QueryObserver<
6868
TQueryKey
6969
>
7070
private previousQueryResult?: QueryObserverResult<TData, TError>
71-
private previousSelectError: Error | null
71+
private previousSelectError: TError | null
7272
private staleTimeoutId?: number
7373
private refetchIntervalId?: number
7474
private currentRefetchInterval?: number | false
@@ -496,8 +496,8 @@ export class QueryObserver<
496496
this.previousSelectError = null
497497
} catch (selectError) {
498498
getLogger().error(selectError)
499-
error = selectError
500-
this.previousSelectError = selectError
499+
error = selectError as TError
500+
this.previousSelectError = selectError as TError
501501
errorUpdatedAt = Date.now()
502502
status = 'error'
503503
}
@@ -539,8 +539,8 @@ export class QueryObserver<
539539
this.previousSelectError = null
540540
} catch (selectError) {
541541
getLogger().error(selectError)
542-
error = selectError
543-
this.previousSelectError = selectError
542+
error = selectError as TError
543+
this.previousSelectError = selectError as TError
544544
errorUpdatedAt = Date.now()
545545
status = 'error'
546546
}

0 commit comments

Comments
 (0)