Skip to content

Commit 5a1e506

Browse files
committed
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 59c5c88 commit 5a1e506

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

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 => {

0 commit comments

Comments
 (0)