Skip to content

Commit

Permalink
fix: align notify terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
boschni committed Oct 7, 2020
1 parent 1f5b13e commit 07d4796
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { act } from '@testing-library/react'

import { setUpdateFn } from './src'
import { setNotifyFn } from './src'

// Wrap updates with act to make sure React knows about React Query updates
setUpdateFn(fn => {
// Wrap notifications with act to make sure React knows about React Query updates
setNotifyFn(fn => {
act(fn)
})
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { QueryCache } from './queryCache'
export { QueryClient } from './queryClient'
export { setBatchUpdatesFn, setUpdateFn } from './notifyManager'
export { setBatchNotifyFn, setNotifyFn } from './notifyManager'
export { setLogger } from './logger'
export { setFocusHandler } from './focusHandler'
export { setOnlineHandler } from './onlineHandler'
Expand Down
38 changes: 19 additions & 19 deletions src/core/notifyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ import { scheduleMicrotask } from './utils'

type NotifyCallback = () => void

type UpdateFunction = (callback: () => void) => void
type NotifyFunction = (callback: () => void) => void

type BatchUpdatesFunction = (callback: () => void) => void
type BatchNotifyFunction = (callback: () => void) => void

// GETTERS AND SETTERS

// Default to a dummy "update" implementation that just runs the callback
let updateFn: UpdateFunction = (callback: () => void) => {
// Default to a dummy "notify" implementation that just runs the callback
let notifyFn: NotifyFunction = (callback: () => void) => {
callback()
}

// Default to a dummy "batch update" implementation that just runs the callback
let batchUpdatesFn: BatchUpdatesFunction = (callback: () => void) => {
// Default to a dummy "batch notify" implementation that just runs the callback
let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {
callback()
}

/**
* Use this function to set a custom update function.
* This can be used to for example wrap updates with `React.act` while running tests.
* Use this function to set a custom notify function.
* This can be used to for example wrap notifications with `React.act` while running tests.
*/
export function setUpdateFn(fn: UpdateFunction) {
updateFn = fn
export function setNotifyFn(fn: NotifyFunction) {
notifyFn = fn
}

/**
* Use this function to set a custom batch function to batch updates together into a single render pass.
* Use this function to set a custom function to batch notifications together into a single tick.
* By default React Query will use the batch function provided by ReactDOM or React Native.
*/
export function setBatchUpdatesFn(fn: BatchUpdatesFunction) {
batchUpdatesFn = fn
export function setBatchNotifyFn(fn: BatchNotifyFunction) {
batchNotifyFn = fn
}

// CLASS
Expand All @@ -57,12 +57,12 @@ class NotifyManager {
return result
}

schedule(notify: NotifyCallback): void {
schedule(callback: NotifyCallback): void {
if (this.transactions) {
this.queue.push(notify)
this.queue.push(callback)
} else {
scheduleMicrotask(() => {
updateFn(notify)
notifyFn(callback)
})
}
}
Expand All @@ -72,9 +72,9 @@ class NotifyManager {
this.queue = []
if (queue.length) {
scheduleMicrotask(() => {
batchUpdatesFn(() => {
queue.forEach(notify => {
updateFn(notify)
batchNotifyFn(() => {
queue.forEach(callback => {
notifyFn(callback)
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/react/setBatchUpdatesFn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setBatchUpdatesFn } from '../core'
import { setBatchNotifyFn } from '../core'
import { unstable_batchedUpdates } from './reactBatchedUpdates'

setBatchUpdatesFn(unstable_batchedUpdates)
setBatchNotifyFn(unstable_batchedUpdates)

0 comments on commit 07d4796

Please sign in to comment.