All files / src/hooks/off off.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 394x                                                                     4x 4x    
import { slot } from '../slot'
 
import type { Event, Listener, Rune } from '../../RuneHub'
 
/**
 * Deactivates a rune and removes all its dependencies.
 * Cleans up dependency relationships but does not remove event listeners.
 * @param rune - The rune to deactivate
 * @example
 * ```ts
 * const count = () => 5
 * const effect = () =>  console.log('Count:', get(count))
 *
 * on(effect) // logs: 'Count: 5'
 * set(count, 10) // logs: 'Count: 10'
 * off(effect) // stop effect
 * set(count, 20) // no log
 * ```
 */
export function off (rune: Rune): void
/**
 * Unsubscribes a specific listener from a rune event.
 * @param rune - The rune to unsubscribe from
 * @param event - The event to unsubscribe from
 * @param listener - The listener function to remove
 * @example
 * ```ts
 * const count = () => 5
 * const listener = () => console.log('changed')
 * on(count, 'change', listener)
 * off(count, 'change', listener) // remove specific listener
 * ```
 */
export function off (rune: Rune, event: Event, listener: Listener): void
 
export function off (rune: Rune, event?: Event, listener?: Listener): void {
  slot(rune).off(event!, listener!)
}