Skip to content
0

katanakit-js / FocusManager

Interface: FocusManager ​

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:10

The FocusManager manages the focus state within TanStack Query.

It can be used to change the default event listeners or to manually change the focus state.

Extends ​

  • Subscribable<Listener>

Properties ​

PropertyModifierTypeInherited fromDefined in
listenersprotectedSet<Listener>Subscribable.listenersnode_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:8

Methods ​

hasListeners() ​

ts
hasListeners(): boolean;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:28

Returns true while at least one listener is registered, false once they have all unsubscribed.

Returns ​

boolean

Inherited from ​

ts
Subscribable.hasListeners

isFocused() ​

ts
isFocused(): boolean;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:67

isFocused can be used to get the current focus state.

Returns ​

boolean


onFocus() ​

ts
onFocus(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:63

onFocus notifies all subscribed listeners with the current focus state.

Returns ​

void


onSubscribe() ​

ts
protected onSubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:13

Returns ​

void

Overrides ​

ts
Subscribable.onSubscribe

onUnsubscribe() ​

ts
protected onUnsubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:14

Returns ​

void

Overrides ​

ts
Subscribable.onUnsubscribe

setEventListener() ​

ts
setEventListener(setup): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:40

setEventListener can be used to set a custom event listener that will be used to determine the focus state. The provided setup function receives a setFocused callback: call it with a boolean to manually set the focus state, or with no arguments to re-evaluate the current focus state and notify subscribers.

Parameters ​

ParameterType
setupSetupFn

Returns ​

void

Example ​

ts
import { focusManager } from '@tanstack/query-core'

focusManager.setEventListener((handleFocus) => {
  const listener = () => handleFocus()
  // Listen to visibilitychange
  if (typeof window !== 'undefined' && window.addEventListener) {
    window.addEventListener('visibilitychange', listener, false)
  }

  return () => {
    // Be sure to unsubscribe if a new handler is set
    window.removeEventListener('visibilitychange', listener)
  }
})

setFocused() ​

ts
setFocused(focused?): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/focusManager.d.ts:59

setFocused can be used to manually set the focus state. Set undefined to fall back to the default focus check.

Parameters ​

ParameterType
focused?boolean

Returns ​

void

Example ​

ts
import { focusManager } from '@tanstack/query-core'

// Set focused
focusManager.setFocused(true)

// Set unfocused
focusManager.setFocused(false)

// Fallback to the default focus check
focusManager.setFocused(undefined)

subscribe() ​

ts
subscribe(listener): () => void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:24

Registers a listener to be called on every update this object notifies about. Returns a function that removes the listener again — call it to stop listening. The base class never drops a listener on its own, though some subclasses clear all of theirs in destroy().

Parameters ​

ParameterTypeDescription
listenerListenerCalled on each update, with whatever the subclass passes to its subscribers.

Returns ​

() => void

Example ​

ts
const unsubscribe = subscribable.subscribe(() => {
  // react to the update
})

unsubscribe()

Inherited from ​

ts
Subscribable.subscribe

Released under the MIT License.