Skip to content

observerCount

The observerCount function allows you to determine the number of observers (callbacks) currently registered on a ref object. This can be useful for debugging and understanding how many entities are actively reacting to changes in the ref object.

To get the number of observers for a ref object, you can use the observerCount function.

import { observerCount, ref } from 'regor'
const myRef = ref('Hello, Regor!')
// Get the observer count
const count = observerCount(myRef)
console.log('Observer count:', count)
  • source: The ref object for which you want to retrieve the observer count.
  • The observerCount function returns the number of observers (callbacks) currently registered on the provided ref object.
import { observerCount, ref, observe } from 'regor'
const myRef = ref('Hello, Regor!')
// Create an observer for the ref
observe(myRef, () => {
console.log('Ref value changed.')
})
// Get the observer count
const count = observerCount(myRef)
console.log('Observer count:', count) // Outputs 'Observer count: 1'

Back to the API list