@pyreon/hooks 0.11.5 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +5 -5
  2. package/lib/index.d.ts +4 -4
  3. package/package.json +24 -24
  4. package/src/__tests__/useBreakpoint.test.ts +48 -48
  5. package/src/__tests__/useClickOutside.test.ts +31 -31
  6. package/src/__tests__/useColorScheme.test.ts +22 -22
  7. package/src/__tests__/useControllableState.test.ts +18 -18
  8. package/src/__tests__/useDebouncedCallback.test.ts +19 -19
  9. package/src/__tests__/useDebouncedValue.test.ts +28 -28
  10. package/src/__tests__/useElementSize.test.ts +21 -21
  11. package/src/__tests__/useFocus.test.ts +12 -12
  12. package/src/__tests__/useFocusTrap.test.ts +36 -36
  13. package/src/__tests__/useHover.test.ts +13 -13
  14. package/src/__tests__/useIntersection.test.ts +20 -20
  15. package/src/__tests__/useInterval.test.ts +7 -7
  16. package/src/__tests__/useIsomorphicLayoutEffect.test.ts +5 -5
  17. package/src/__tests__/useKeyboard.test.ts +38 -38
  18. package/src/__tests__/useLatest.test.ts +11 -11
  19. package/src/__tests__/useMediaQuery.test.ts +29 -29
  20. package/src/__tests__/useMergedRef.test.ts +10 -10
  21. package/src/__tests__/usePrevious.test.ts +20 -20
  22. package/src/__tests__/useReducedMotion.test.ts +15 -15
  23. package/src/__tests__/useRootSize.test.ts +9 -9
  24. package/src/__tests__/useScrollLock.test.ts +33 -33
  25. package/src/__tests__/useSpacing.test.ts +11 -11
  26. package/src/__tests__/useThemeValue.test.ts +5 -5
  27. package/src/__tests__/useThrottledCallback.test.ts +16 -16
  28. package/src/__tests__/useTimeout.test.ts +8 -8
  29. package/src/__tests__/useToggle.test.ts +14 -14
  30. package/src/__tests__/useUpdateEffect.test.ts +8 -8
  31. package/src/__tests__/useWindowResize.test.ts +34 -34
  32. package/src/index.ts +56 -56
  33. package/src/useBreakpoint.ts +6 -6
  34. package/src/useClickOutside.ts +5 -5
  35. package/src/useClipboard.ts +2 -2
  36. package/src/useColorScheme.ts +5 -5
  37. package/src/useControllableState.ts +2 -2
  38. package/src/useDebouncedCallback.ts +1 -1
  39. package/src/useDebouncedValue.ts +2 -2
  40. package/src/useDialog.ts +4 -4
  41. package/src/useElementSize.ts +2 -2
  42. package/src/useEventListener.ts +2 -2
  43. package/src/useFocus.ts +1 -1
  44. package/src/useFocusTrap.ts +4 -4
  45. package/src/useHover.ts +1 -1
  46. package/src/useInfiniteScroll.ts +10 -10
  47. package/src/useIntersection.ts +2 -2
  48. package/src/useInterval.ts +1 -1
  49. package/src/useIsomorphicLayoutEffect.ts +2 -2
  50. package/src/useKeyboard.ts +3 -3
  51. package/src/useMediaQuery.ts +4 -4
  52. package/src/useMergedRef.ts +1 -1
  53. package/src/useOnline.ts +6 -6
  54. package/src/usePrevious.ts +1 -1
  55. package/src/useReducedMotion.ts +2 -2
  56. package/src/useRootSize.ts +1 -1
  57. package/src/useScrollLock.ts +3 -3
  58. package/src/useSpacing.ts +1 -1
  59. package/src/useThemeValue.ts +2 -2
  60. package/src/useThrottledCallback.ts +2 -2
  61. package/src/useTimeAgo.ts +15 -15
  62. package/src/useTimeout.ts +1 -1
  63. package/src/useToggle.ts +1 -1
  64. package/src/useUpdateEffect.ts +2 -2
  65. package/src/useWindowResize.ts +6 -6
@@ -1,44 +1,44 @@
1
- import { describe, expect, it, vi } from "vitest"
2
- import { useMergedRef } from "../useMergedRef"
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { useMergedRef } from '../useMergedRef'
3
3
 
4
- describe("useMergedRef", () => {
5
- it("sets object refs", () => {
4
+ describe('useMergedRef', () => {
5
+ it('sets object refs', () => {
6
6
  const ref1 = { current: null as HTMLDivElement | null }
7
7
  const ref2 = { current: null as HTMLDivElement | null }
8
8
 
9
9
  const merged = useMergedRef(ref1, ref2)
10
10
 
11
- const node = document.createElement("div")
11
+ const node = document.createElement('div')
12
12
  merged(node)
13
13
 
14
14
  expect(ref1.current).toBe(node)
15
15
  expect(ref2.current).toBe(node)
16
16
  })
17
17
 
18
- it("calls callback refs", () => {
18
+ it('calls callback refs', () => {
19
19
  const cb = vi.fn()
20
20
  const objRef = { current: null as HTMLDivElement | null }
21
21
 
22
22
  const merged = useMergedRef(cb, objRef)
23
23
 
24
- const node = document.createElement("div")
24
+ const node = document.createElement('div')
25
25
  merged(node)
26
26
 
27
27
  expect(cb).toHaveBeenCalledWith(node)
28
28
  expect(objRef.current).toBe(node)
29
29
  })
30
30
 
31
- it("skips undefined refs", () => {
31
+ it('skips undefined refs', () => {
32
32
  const ref = { current: null as HTMLDivElement | null }
33
33
  const merged = useMergedRef(undefined, ref)
34
34
 
35
- const node = document.createElement("div")
35
+ const node = document.createElement('div')
36
36
  merged(node)
37
37
 
38
38
  expect(ref.current).toBe(node)
39
39
  })
40
40
 
41
- it("handles null node (unmount)", () => {
41
+ it('handles null node (unmount)', () => {
42
42
  const cb = vi.fn()
43
43
  const merged = useMergedRef(cb)
44
44
 
@@ -1,15 +1,15 @@
1
- import { signal } from "@pyreon/reactivity"
2
- import { describe, expect, it } from "vitest"
3
- import { usePrevious } from "../usePrevious"
1
+ import { signal } from '@pyreon/reactivity'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { usePrevious } from '../usePrevious'
4
4
 
5
- describe("usePrevious", () => {
6
- it("returns undefined initially", () => {
5
+ describe('usePrevious', () => {
6
+ it('returns undefined initially', () => {
7
7
  const source = signal(1)
8
8
  const prev = usePrevious(source)
9
9
  expect(prev()).toBeUndefined()
10
10
  })
11
11
 
12
- it("returns the previous value after source changes", () => {
12
+ it('returns the previous value after source changes', () => {
13
13
  const source = signal(1)
14
14
  const prev = usePrevious(source)
15
15
  expect(prev()).toBeUndefined()
@@ -18,22 +18,22 @@ describe("usePrevious", () => {
18
18
  expect(prev()).toBe(1)
19
19
  })
20
20
 
21
- it("tracks multiple changes", () => {
22
- const source = signal("a")
21
+ it('tracks multiple changes', () => {
22
+ const source = signal('a')
23
23
  const prev = usePrevious(source)
24
24
  expect(prev()).toBeUndefined()
25
25
 
26
- source.set("b")
27
- expect(prev()).toBe("a")
26
+ source.set('b')
27
+ expect(prev()).toBe('a')
28
28
 
29
- source.set("c")
30
- expect(prev()).toBe("b")
29
+ source.set('c')
30
+ expect(prev()).toBe('b')
31
31
 
32
- source.set("d")
33
- expect(prev()).toBe("c")
32
+ source.set('d')
33
+ expect(prev()).toBe('c')
34
34
  })
35
35
 
36
- it("works with number values", () => {
36
+ it('works with number values', () => {
37
37
  const source = signal(10)
38
38
  const prev = usePrevious(source)
39
39
  expect(prev()).toBeUndefined()
@@ -45,7 +45,7 @@ describe("usePrevious", () => {
45
45
  expect(prev()).toBe(20)
46
46
  })
47
47
 
48
- it("works with object values", () => {
48
+ it('works with object values', () => {
49
49
  const obj1 = { x: 1 }
50
50
  const obj2 = { x: 2 }
51
51
  const source = signal(obj1)
@@ -56,15 +56,15 @@ describe("usePrevious", () => {
56
56
  expect(prev()).toBe(obj1)
57
57
  })
58
58
 
59
- it("works with null values", () => {
60
- const source = signal<string | null>("hello")
59
+ it('works with null values', () => {
60
+ const source = signal<string | null>('hello')
61
61
  const prev = usePrevious(source)
62
62
  expect(prev()).toBeUndefined()
63
63
 
64
64
  source.set(null)
65
- expect(prev()).toBe("hello")
65
+ expect(prev()).toBe('hello')
66
66
 
67
- source.set("world")
67
+ source.set('world')
68
68
  expect(prev()).toBeNull()
69
69
  })
70
70
  })
@@ -1,9 +1,9 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest"
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
2
 
3
3
  let mountCallbacks: Array<() => unknown> = []
4
4
  let unmountCallbacks: Array<() => void> = []
5
5
 
6
- vi.mock("@pyreon/core", () => ({
6
+ vi.mock('@pyreon/core', () => ({
7
7
  onMount: (fn: () => unknown) => {
8
8
  mountCallbacks.push(fn)
9
9
  },
@@ -12,9 +12,9 @@ vi.mock("@pyreon/core", () => ({
12
12
  },
13
13
  }))
14
14
 
15
- import { useReducedMotion } from "../useReducedMotion"
15
+ import { useReducedMotion } from '../useReducedMotion'
16
16
 
17
- describe("useReducedMotion", () => {
17
+ describe('useReducedMotion', () => {
18
18
  let changeListeners: Map<string, (e: MediaQueryListEvent) => void>
19
19
 
20
20
  beforeEach(() => {
@@ -22,20 +22,20 @@ describe("useReducedMotion", () => {
22
22
  unmountCallbacks = []
23
23
  changeListeners = new Map()
24
24
 
25
- Object.defineProperty(window, "matchMedia", {
25
+ Object.defineProperty(window, 'matchMedia', {
26
26
  writable: true,
27
27
  value: vi.fn((query: string) => ({
28
28
  matches: false,
29
29
  media: query,
30
30
  addEventListener: vi.fn((event: string, cb: (e: MediaQueryListEvent) => void) => {
31
- if (event === "change") changeListeners.set(query, cb)
31
+ if (event === 'change') changeListeners.set(query, cb)
32
32
  }),
33
33
  removeEventListener: vi.fn(),
34
34
  })),
35
35
  })
36
36
  })
37
37
 
38
- it("returns false when no motion preference", () => {
38
+ it('returns false when no motion preference', () => {
39
39
  const reduced = useReducedMotion()
40
40
  mountCallbacks.forEach((cb) => {
41
41
  cb()
@@ -43,14 +43,14 @@ describe("useReducedMotion", () => {
43
43
  expect(reduced()).toBe(false)
44
44
  })
45
45
 
46
- it("returns true when reduced motion is preferred", () => {
47
- Object.defineProperty(window, "matchMedia", {
46
+ it('returns true when reduced motion is preferred', () => {
47
+ Object.defineProperty(window, 'matchMedia', {
48
48
  writable: true,
49
49
  value: vi.fn((query: string) => ({
50
50
  matches: true,
51
51
  media: query,
52
52
  addEventListener: vi.fn((event: string, cb: (e: MediaQueryListEvent) => void) => {
53
- if (event === "change") changeListeners.set(query, cb)
53
+ if (event === 'change') changeListeners.set(query, cb)
54
54
  }),
55
55
  removeEventListener: vi.fn(),
56
56
  })),
@@ -63,26 +63,26 @@ describe("useReducedMotion", () => {
63
63
  expect(reduced()).toBe(true)
64
64
  })
65
65
 
66
- it("updates when preference changes", () => {
66
+ it('updates when preference changes', () => {
67
67
  const reduced = useReducedMotion()
68
68
  mountCallbacks.forEach((cb) => {
69
69
  cb()
70
70
  })
71
71
  expect(reduced()).toBe(false)
72
72
 
73
- const listener = changeListeners.get("(prefers-reduced-motion: reduce)")
73
+ const listener = changeListeners.get('(prefers-reduced-motion: reduce)')
74
74
  listener?.({ matches: true } as MediaQueryListEvent)
75
75
  expect(reduced()).toBe(true)
76
76
  })
77
77
 
78
- it("queries the correct media string", () => {
78
+ it('queries the correct media string', () => {
79
79
  const matchMediaSpy = vi.fn((query: string) => ({
80
80
  matches: false,
81
81
  media: query,
82
82
  addEventListener: vi.fn(),
83
83
  removeEventListener: vi.fn(),
84
84
  }))
85
- Object.defineProperty(window, "matchMedia", {
85
+ Object.defineProperty(window, 'matchMedia', {
86
86
  writable: true,
87
87
  value: matchMediaSpy,
88
88
  })
@@ -91,6 +91,6 @@ describe("useReducedMotion", () => {
91
91
  mountCallbacks.forEach((cb) => {
92
92
  cb()
93
93
  })
94
- expect(matchMediaSpy).toHaveBeenCalledWith("(prefers-reduced-motion: reduce)")
94
+ expect(matchMediaSpy).toHaveBeenCalledWith('(prefers-reduced-motion: reduce)')
95
95
  })
96
96
  })
@@ -1,25 +1,25 @@
1
- import { describe, expect, it, vi } from "vitest"
1
+ import { describe, expect, it, vi } from 'vitest'
2
2
 
3
3
  // Mock @pyreon/styler to provide theme values
4
- vi.mock("@pyreon/styler", () => ({
4
+ vi.mock('@pyreon/styler', () => ({
5
5
  useTheme: () => ({}),
6
6
  }))
7
7
 
8
- import { useRootSize } from "../useRootSize"
8
+ import { useRootSize } from '../useRootSize'
9
9
 
10
- describe("useRootSize", () => {
11
- it("defaults rootSize to 16", () => {
10
+ describe('useRootSize', () => {
11
+ it('defaults rootSize to 16', () => {
12
12
  const result = useRootSize()
13
13
  expect(result.rootSize).toBe(16)
14
14
  })
15
15
 
16
- it("pxToRem converts correctly with default rootSize", () => {
16
+ it('pxToRem converts correctly with default rootSize', () => {
17
17
  const result = useRootSize()
18
- expect(result.pxToRem(32)).toBe("2rem")
19
- expect(result.pxToRem(8)).toBe("0.5rem")
18
+ expect(result.pxToRem(32)).toBe('2rem')
19
+ expect(result.pxToRem(8)).toBe('0.5rem')
20
20
  })
21
21
 
22
- it("remToPx converts correctly with default rootSize", () => {
22
+ it('remToPx converts correctly with default rootSize', () => {
23
23
  const result = useRootSize()
24
24
  expect(result.remToPx(2)).toBe(32)
25
25
  expect(result.remToPx(0.5)).toBe(8)
@@ -1,6 +1,6 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
 
3
- vi.mock("@pyreon/core", () => ({
3
+ vi.mock('@pyreon/core', () => ({
4
4
  onMount: (_fn: () => unknown) => {
5
5
  /* no-op */
6
6
  },
@@ -9,19 +9,19 @@ vi.mock("@pyreon/core", () => ({
9
9
  },
10
10
  }))
11
11
 
12
- describe("useScrollLock", () => {
12
+ describe('useScrollLock', () => {
13
13
  beforeEach(async () => {
14
14
  vi.resetModules()
15
- document.body.style.overflow = ""
15
+ document.body.style.overflow = ''
16
16
  })
17
17
 
18
18
  afterEach(() => {
19
- document.body.style.overflow = ""
19
+ document.body.style.overflow = ''
20
20
  })
21
21
 
22
22
  async function getUseScrollLock() {
23
23
  // Re-mock after resetModules
24
- vi.doMock("@pyreon/core", () => ({
24
+ vi.doMock('@pyreon/core', () => ({
25
25
  onMount: (_fn: () => unknown) => {
26
26
  /* no-op */
27
27
  },
@@ -29,76 +29,76 @@ describe("useScrollLock", () => {
29
29
  /* no-op */
30
30
  },
31
31
  }))
32
- const mod = await import("../useScrollLock")
32
+ const mod = await import('../useScrollLock')
33
33
  return mod.useScrollLock
34
34
  }
35
35
 
36
- it("sets overflow to hidden when locked", async () => {
36
+ it('sets overflow to hidden when locked', async () => {
37
37
  const useScrollLock = await getUseScrollLock()
38
38
  const { lock } = useScrollLock()
39
39
  lock()
40
- expect(document.body.style.overflow).toBe("hidden")
40
+ expect(document.body.style.overflow).toBe('hidden')
41
41
  })
42
42
 
43
- it("does not change overflow until lock is called", async () => {
43
+ it('does not change overflow until lock is called', async () => {
44
44
  const useScrollLock = await getUseScrollLock()
45
- document.body.style.overflow = "auto"
45
+ document.body.style.overflow = 'auto'
46
46
  useScrollLock()
47
- expect(document.body.style.overflow).toBe("auto")
47
+ expect(document.body.style.overflow).toBe('auto')
48
48
  })
49
49
 
50
- it("restores overflow when unlocked", async () => {
50
+ it('restores overflow when unlocked', async () => {
51
51
  const useScrollLock = await getUseScrollLock()
52
- document.body.style.overflow = "auto"
52
+ document.body.style.overflow = 'auto'
53
53
  const { lock, unlock } = useScrollLock()
54
54
  lock()
55
- expect(document.body.style.overflow).toBe("hidden")
55
+ expect(document.body.style.overflow).toBe('hidden')
56
56
  unlock()
57
- expect(document.body.style.overflow).toBe("auto")
57
+ expect(document.body.style.overflow).toBe('auto')
58
58
  })
59
59
 
60
- it("lock is idempotent", async () => {
60
+ it('lock is idempotent', async () => {
61
61
  const useScrollLock = await getUseScrollLock()
62
62
  const { lock, unlock } = useScrollLock()
63
63
  lock()
64
64
  lock() // second call should be no-op
65
- expect(document.body.style.overflow).toBe("hidden")
65
+ expect(document.body.style.overflow).toBe('hidden')
66
66
  unlock()
67
- expect(document.body.style.overflow).toBe("")
67
+ expect(document.body.style.overflow).toBe('')
68
68
  })
69
69
 
70
- it("unlock is idempotent", async () => {
70
+ it('unlock is idempotent', async () => {
71
71
  const useScrollLock = await getUseScrollLock()
72
72
  const { lock, unlock } = useScrollLock()
73
73
  lock()
74
74
  unlock()
75
75
  unlock() // second call should be no-op
76
- expect(document.body.style.overflow).toBe("")
76
+ expect(document.body.style.overflow).toBe('')
77
77
  })
78
78
 
79
- it("handles concurrent locks with reference counting", async () => {
79
+ it('handles concurrent locks with reference counting', async () => {
80
80
  const useScrollLock = await getUseScrollLock()
81
81
  const lock1 = useScrollLock()
82
82
  const lock2 = useScrollLock()
83
83
 
84
84
  lock1.lock()
85
- expect(document.body.style.overflow).toBe("hidden")
85
+ expect(document.body.style.overflow).toBe('hidden')
86
86
 
87
87
  lock2.lock()
88
- expect(document.body.style.overflow).toBe("hidden")
88
+ expect(document.body.style.overflow).toBe('hidden')
89
89
 
90
90
  // Unlocking first should not restore (still 1 active)
91
91
  lock1.unlock()
92
- expect(document.body.style.overflow).toBe("hidden")
92
+ expect(document.body.style.overflow).toBe('hidden')
93
93
 
94
94
  // Unlocking second should restore
95
95
  lock2.unlock()
96
- expect(document.body.style.overflow).toBe("")
96
+ expect(document.body.style.overflow).toBe('')
97
97
  })
98
98
 
99
- it("preserves original overflow across concurrent locks", async () => {
99
+ it('preserves original overflow across concurrent locks', async () => {
100
100
  const useScrollLock = await getUseScrollLock()
101
- document.body.style.overflow = "scroll"
101
+ document.body.style.overflow = 'scroll'
102
102
 
103
103
  const lock1 = useScrollLock()
104
104
  const lock2 = useScrollLock()
@@ -107,17 +107,17 @@ describe("useScrollLock", () => {
107
107
  lock2.lock()
108
108
 
109
109
  lock1.unlock()
110
- expect(document.body.style.overflow).toBe("hidden")
110
+ expect(document.body.style.overflow).toBe('hidden')
111
111
 
112
112
  lock2.unlock()
113
- expect(document.body.style.overflow).toBe("scroll")
113
+ expect(document.body.style.overflow).toBe('scroll')
114
114
  })
115
115
 
116
- it("unlock without prior lock is no-op", async () => {
116
+ it('unlock without prior lock is no-op', async () => {
117
117
  const useScrollLock = await getUseScrollLock()
118
- document.body.style.overflow = "auto"
118
+ document.body.style.overflow = 'auto'
119
119
  const { unlock } = useScrollLock()
120
120
  unlock()
121
- expect(document.body.style.overflow).toBe("auto")
121
+ expect(document.body.style.overflow).toBe('auto')
122
122
  })
123
123
  })
@@ -1,23 +1,23 @@
1
- import { describe, expect, it, vi } from "vitest"
1
+ import { describe, expect, it, vi } from 'vitest'
2
2
 
3
3
  // Mock @pyreon/styler to provide theme values
4
- vi.mock("@pyreon/styler", () => ({
4
+ vi.mock('@pyreon/styler', () => ({
5
5
  useTheme: () => ({}),
6
6
  }))
7
7
 
8
- import { useSpacing } from "../useSpacing"
8
+ import { useSpacing } from '../useSpacing'
9
9
 
10
- describe("useSpacing", () => {
11
- it("returns spacing function with default base (rootSize/2 = 8)", () => {
10
+ describe('useSpacing', () => {
11
+ it('returns spacing function with default base (rootSize/2 = 8)', () => {
12
12
  const spacing = useSpacing()
13
- expect(spacing(1)).toBe("8px")
14
- expect(spacing(2)).toBe("16px")
15
- expect(spacing(0.5)).toBe("4px")
13
+ expect(spacing(1)).toBe('8px')
14
+ expect(spacing(2)).toBe('16px')
15
+ expect(spacing(0.5)).toBe('4px')
16
16
  })
17
17
 
18
- it("accepts custom base unit", () => {
18
+ it('accepts custom base unit', () => {
19
19
  const spacing = useSpacing(4)
20
- expect(spacing(1)).toBe("4px")
21
- expect(spacing(3)).toBe("12px")
20
+ expect(spacing(1)).toBe('4px')
21
+ expect(spacing(3)).toBe('12px')
22
22
  })
23
23
  })
@@ -1,12 +1,12 @@
1
- import { describe, expect, it } from "vitest"
2
- import { useThemeValue } from "../useThemeValue"
1
+ import { describe, expect, it } from 'vitest'
2
+ import { useThemeValue } from '../useThemeValue'
3
3
 
4
4
  // Without a ThemeProvider, useTheme returns the default (empty object {}).
5
5
  // So get(theme, path) returns undefined for any path.
6
6
 
7
- describe("useThemeValue", () => {
8
- it("returns undefined when no theme values exist", () => {
9
- const result = useThemeValue("colors.primary")
7
+ describe('useThemeValue', () => {
8
+ it('returns undefined when no theme values exist', () => {
9
+ const result = useThemeValue('colors.primary')
10
10
  expect(result).toBeUndefined()
11
11
  })
12
12
  })
@@ -1,8 +1,8 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
 
3
3
  // Mock @pyreon/core partially - keep real exports but stub lifecycle hooks
4
- vi.mock("@pyreon/core", async (importOriginal) => {
5
- const actual = await importOriginal<typeof import("@pyreon/core")>()
4
+ vi.mock('@pyreon/core', async (importOriginal) => {
5
+ const actual = await importOriginal<typeof import('@pyreon/core')>()
6
6
  return {
7
7
  ...actual,
8
8
  onMount: (fn: () => void) => fn(),
@@ -12,42 +12,42 @@ vi.mock("@pyreon/core", async (importOriginal) => {
12
12
  }
13
13
  })
14
14
 
15
- import { useThrottledCallback } from "../useThrottledCallback"
15
+ import { useThrottledCallback } from '../useThrottledCallback'
16
16
 
17
- describe("useThrottledCallback", () => {
17
+ describe('useThrottledCallback', () => {
18
18
  beforeEach(() => vi.useFakeTimers())
19
19
  afterEach(() => vi.useRealTimers())
20
20
 
21
- it("calls immediately on first invocation (leading)", () => {
21
+ it('calls immediately on first invocation (leading)', () => {
22
22
  const fn = vi.fn()
23
23
  const throttled = useThrottledCallback(fn, 100)
24
24
 
25
- throttled("a")
25
+ throttled('a')
26
26
  expect(fn).toHaveBeenCalledTimes(1)
27
- expect(fn).toHaveBeenCalledWith("a")
27
+ expect(fn).toHaveBeenCalledWith('a')
28
28
  })
29
29
 
30
- it("throttles subsequent calls", () => {
30
+ it('throttles subsequent calls', () => {
31
31
  const fn = vi.fn()
32
32
  const throttled = useThrottledCallback(fn, 100)
33
33
 
34
- throttled("a")
35
- throttled("b")
36
- throttled("c")
34
+ throttled('a')
35
+ throttled('b')
36
+ throttled('c')
37
37
 
38
38
  expect(fn).toHaveBeenCalledTimes(1)
39
39
 
40
40
  vi.advanceTimersByTime(100)
41
41
  expect(fn).toHaveBeenCalledTimes(2)
42
- expect(fn).toHaveBeenLastCalledWith("c")
42
+ expect(fn).toHaveBeenLastCalledWith('c')
43
43
  })
44
44
 
45
- it("cancel stops pending trailing call", () => {
45
+ it('cancel stops pending trailing call', () => {
46
46
  const fn = vi.fn()
47
47
  const throttled = useThrottledCallback(fn, 100)
48
48
 
49
- throttled("a")
50
- throttled("b")
49
+ throttled('a')
50
+ throttled('b')
51
51
  throttled.cancel()
52
52
 
53
53
  vi.advanceTimersByTime(200)
@@ -1,19 +1,19 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
2
- import { useTimeout } from "../useTimeout"
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { useTimeout } from '../useTimeout'
3
3
 
4
4
  // Mock onUnmount since it requires component lifecycle context
5
- vi.mock("@pyreon/core", () => ({
5
+ vi.mock('@pyreon/core', () => ({
6
6
  onMount: (fn: () => void) => fn(),
7
7
  onUnmount: (_fn: () => void) => {
8
8
  /* no-op */
9
9
  },
10
10
  }))
11
11
 
12
- describe("useTimeout", () => {
12
+ describe('useTimeout', () => {
13
13
  beforeEach(() => vi.useFakeTimers())
14
14
  afterEach(() => vi.useRealTimers())
15
15
 
16
- it("calls callback after delay", () => {
16
+ it('calls callback after delay', () => {
17
17
  const fn = vi.fn()
18
18
  useTimeout(fn, 200)
19
19
 
@@ -21,7 +21,7 @@ describe("useTimeout", () => {
21
21
  expect(fn).toHaveBeenCalledTimes(1)
22
22
  })
23
23
 
24
- it("does not call callback when delay is null", () => {
24
+ it('does not call callback when delay is null', () => {
25
25
  const fn = vi.fn()
26
26
  useTimeout(fn, null)
27
27
 
@@ -29,7 +29,7 @@ describe("useTimeout", () => {
29
29
  expect(fn).not.toHaveBeenCalled()
30
30
  })
31
31
 
32
- it("clear() prevents the callback", () => {
32
+ it('clear() prevents the callback', () => {
33
33
  const fn = vi.fn()
34
34
  const { clear } = useTimeout(fn, 200)
35
35
 
@@ -38,7 +38,7 @@ describe("useTimeout", () => {
38
38
  expect(fn).not.toHaveBeenCalled()
39
39
  })
40
40
 
41
- it("reset() restarts the timer", () => {
41
+ it('reset() restarts the timer', () => {
42
42
  const fn = vi.fn()
43
43
  const { reset } = useTimeout(fn, 200)
44
44