muya 2.5.4 → 2.5.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 (123) hide show
  1. package/{src/__tests__ → __tests__}/bench.test.tsx +4 -4
  2. package/{src/__tests__ → __tests__}/compare.test.tsx +8 -6
  3. package/{src/__tests__ → __tests__}/create.test.tsx +2 -2
  4. package/{src/utils/__tests__ → __tests__}/is.test.ts +3 -3
  5. package/{src/__tests__ → __tests__}/scheduler.test.tsx +1 -1
  6. package/{src/__tests__ → __tests__}/select.test.tsx +5 -5
  7. package/{src/utils/__tests__ → __tests__}/shallow.test.ts +1 -1
  8. package/{src/__tests__ → __tests__}/use-value-loadable.test.tsx +3 -3
  9. package/{src/__tests__ → __tests__}/use-value.test.tsx +8 -8
  10. package/build.ts +67 -0
  11. package/dist/cjs/index.js +14 -0
  12. package/dist/esm/create.js +1 -0
  13. package/dist/esm/debug/development-tools.js +1 -0
  14. package/dist/esm/index.js +1 -0
  15. package/dist/esm/scheduler.js +1 -0
  16. package/dist/esm/select.js +1 -0
  17. package/{types → dist/types}/create-state.d.ts +1 -0
  18. package/dist/types/create-state.d.ts.map +1 -0
  19. package/{types → dist/types}/create.d.ts +2 -4
  20. package/dist/types/create.d.ts.map +1 -0
  21. package/dist/types/debug/development-tools.d.ts +13 -0
  22. package/dist/types/debug/development-tools.d.ts.map +1 -0
  23. package/{types → dist/types}/index.d.ts +3 -1
  24. package/dist/types/index.d.ts.map +1 -0
  25. package/dist/types/scheduler.d.ts +25 -0
  26. package/dist/types/scheduler.d.ts.map +1 -0
  27. package/{types → dist/types}/select.d.ts +1 -0
  28. package/dist/types/select.d.ts.map +1 -0
  29. package/{types → dist/types}/types.d.ts +1 -0
  30. package/dist/types/types.d.ts.map +1 -0
  31. package/{types → dist/types}/use-value-loadable.d.ts +1 -0
  32. package/dist/types/use-value-loadable.d.ts.map +1 -0
  33. package/{types → dist/types}/use-value.d.ts +2 -1
  34. package/dist/types/use-value.d.ts.map +1 -0
  35. package/{types → dist/types}/utils/common.d.ts +1 -0
  36. package/dist/types/utils/common.d.ts.map +1 -0
  37. package/{types → dist/types}/utils/create-emitter.d.ts +1 -0
  38. package/dist/types/utils/create-emitter.d.ts.map +1 -0
  39. package/{types → dist/types}/utils/id.d.ts +1 -0
  40. package/dist/types/utils/id.d.ts.map +1 -0
  41. package/{types → dist/types}/utils/is.d.ts +1 -0
  42. package/dist/types/utils/is.d.ts.map +1 -0
  43. package/{types → dist/types}/utils/shallow.d.ts +1 -0
  44. package/dist/types/utils/shallow.d.ts.map +1 -0
  45. package/package.json +31 -8
  46. package/src/create.ts +7 -2
  47. package/src/debug/development-tools.ts +5 -40
  48. package/src/index.ts +2 -1
  49. package/src/scheduler.ts +77 -71
  50. package/src/select.ts +7 -2
  51. package/src/use-value.ts +1 -1
  52. package/tsconfig.build.json +12 -0
  53. package/cjs/index.js +0 -1
  54. package/esm/__tests__/test-utils.js +0 -1
  55. package/esm/create.js +0 -1
  56. package/esm/debug/development-tools.js +0 -1
  57. package/esm/index.js +0 -1
  58. package/esm/scheduler.js +0 -1
  59. package/esm/select.js +0 -1
  60. package/esm/sqlite/__tests__/create-sqlite.test.js +0 -1
  61. package/esm/sqlite/__tests__/map-deque.test.js +0 -1
  62. package/esm/sqlite/__tests__/table.test.js +0 -1
  63. package/esm/sqlite/__tests__/tokenizer.test.js +0 -1
  64. package/esm/sqlite/__tests__/where.test.js +0 -1
  65. package/esm/sqlite/create-sqlite.js +0 -1
  66. package/esm/sqlite/index.js +0 -1
  67. package/esm/sqlite/table/backend.js +0 -1
  68. package/esm/sqlite/table/bun-backend.js +0 -1
  69. package/esm/sqlite/table/index.js +0 -1
  70. package/esm/sqlite/table/map-deque.js +0 -1
  71. package/esm/sqlite/table/table.js +0 -43
  72. package/esm/sqlite/table/table.types.js +0 -0
  73. package/esm/sqlite/table/tokenizer.js +0 -1
  74. package/esm/sqlite/table/where.js +0 -1
  75. package/esm/sqlite/use-sqlite-count.js +0 -1
  76. package/esm/sqlite/use-sqlite.js +0 -1
  77. package/esm/utils/__tests__/is.test.js +0 -1
  78. package/esm/utils/__tests__/shallow.test.js +0 -1
  79. package/src/sqlite/__tests__/create-sqlite.test.ts +0 -264
  80. package/src/sqlite/__tests__/map-deque.test.ts +0 -61
  81. package/src/sqlite/__tests__/table.test.ts +0 -351
  82. package/src/sqlite/__tests__/tokenizer.test.ts +0 -43
  83. package/src/sqlite/__tests__/use-slite-count.test.tsx +0 -96
  84. package/src/sqlite/__tests__/use-sqlite.more.test.tsx +0 -637
  85. package/src/sqlite/__tests__/use-sqlite.test.tsx +0 -1008
  86. package/src/sqlite/__tests__/where.test.ts +0 -234
  87. package/src/sqlite/create-sqlite.ts +0 -164
  88. package/src/sqlite/index.ts +0 -4
  89. package/src/sqlite/table/backend.ts +0 -21
  90. package/src/sqlite/table/bun-backend.ts +0 -47
  91. package/src/sqlite/table/index.ts +0 -6
  92. package/src/sqlite/table/map-deque.ts +0 -29
  93. package/src/sqlite/table/table.ts +0 -353
  94. package/src/sqlite/table/table.types.ts +0 -129
  95. package/src/sqlite/table/tokenizer.ts +0 -35
  96. package/src/sqlite/table/where.ts +0 -207
  97. package/src/sqlite/use-sqlite-count.ts +0 -69
  98. package/src/sqlite/use-sqlite.ts +0 -250
  99. package/types/__tests__/test-utils.d.ts +0 -25
  100. package/types/debug/development-tools.d.ts +0 -8
  101. package/types/scheduler.d.ts +0 -20
  102. package/types/sqlite/create-sqlite.d.ts +0 -31
  103. package/types/sqlite/index.d.ts +0 -4
  104. package/types/sqlite/table/backend.d.ts +0 -20
  105. package/types/sqlite/table/bun-backend.d.ts +0 -6
  106. package/types/sqlite/table/index.d.ts +0 -6
  107. package/types/sqlite/table/map-deque.d.ts +0 -5
  108. package/types/sqlite/table/table.d.ts +0 -21
  109. package/types/sqlite/table/table.types.d.ts +0 -91
  110. package/types/sqlite/table/tokenizer.d.ts +0 -11
  111. package/types/sqlite/table/where.d.ts +0 -37
  112. package/types/sqlite/use-sqlite-count.d.ts +0 -17
  113. package/types/sqlite/use-sqlite.d.ts +0 -39
  114. /package/{src/__tests__ → __tests__}/test-utils.ts +0 -0
  115. /package/{esm → dist/esm}/create-state.js +0 -0
  116. /package/{esm → dist/esm}/types.js +0 -0
  117. /package/{esm → dist/esm}/use-value-loadable.js +0 -0
  118. /package/{esm → dist/esm}/use-value.js +0 -0
  119. /package/{esm → dist/esm}/utils/common.js +0 -0
  120. /package/{esm → dist/esm}/utils/create-emitter.js +0 -0
  121. /package/{esm → dist/esm}/utils/id.js +0 -0
  122. /package/{esm → dist/esm}/utils/is.js +0 -0
  123. /package/{esm → dist/esm}/utils/shallow.js +0 -0
@@ -5,12 +5,12 @@
5
5
  /* eslint-disable unicorn/consistent-function-scoping */
6
6
  /* eslint-disable no-console */
7
7
 
8
- import { act, renderHook } from '@testing-library/react-hooks'
8
+ import { act, renderHook, waitFor } from '@testing-library/react'
9
9
  import { useStore, create as zustand } from 'zustand'
10
10
  import { useEffect, useState } from 'react'
11
- import { useValue } from '../use-value'
11
+ import { useValue } from '../src/use-value'
12
12
  import { atom, useAtom } from 'jotai'
13
- import { create } from '../create'
13
+ import { create } from '../src/create'
14
14
 
15
15
  /**
16
16
  * Utility to render a hook and measure the time it takes to reach a certain state
@@ -25,7 +25,7 @@ function renderPerfHook<T>(hook: () => T, getValue: (data: T) => number, toBe: n
25
25
  onResolve = resolve
26
26
  })
27
27
  const start = performance.now()
28
- const { result, waitFor } = renderHook(() => {
28
+ const { result } = renderHook(() => {
29
29
  const data = hook()
30
30
  const count = getValue(data)
31
31
  useEffect(() => {
@@ -1,5 +1,5 @@
1
- import { act, renderHook } from '@testing-library/react-hooks'
2
- import { create } from '../create'
1
+ import { act, renderHook } from '@testing-library/react'
2
+ import { create } from '../src/create'
3
3
  import { longPromise } from './test-utils'
4
4
  import { waitFor } from '@testing-library/react'
5
5
  import { atom, useAtom, useSetAtom } from 'jotai'
@@ -20,18 +20,20 @@ describe('compare', () => {
20
20
 
21
21
  await waitFor(() => {
22
22
  expect(result.current).toBe(2)
23
- expect(listen).toHaveBeenCalledTimes(2)
23
+ // React 19 renders 3 times due to suspense changes
24
+ expect(listen).toHaveBeenCalledTimes(3)
24
25
  })
25
26
 
26
27
  state.set(1)
27
28
 
28
29
  await waitFor(() => {
29
30
  expect(result.current).toBe(3)
30
- // muya re-render only 3 times
31
- expect(listen).toHaveBeenCalledTimes(3)
31
+ // React 19 - 4 renders total
32
+ expect(listen).toHaveBeenCalledTimes(4)
32
33
  })
33
34
  })
34
- it('should render async value with sync selector with jotai', async () => {
35
+ // Skip Jotai comparison test - not compatible with React 19 without additional setup
36
+ it.skip('should render async value with sync selector with jotai', async () => {
35
37
  const state = atom(longPromise(100))
36
38
 
37
39
  const selectedState = atom(async (get) => {
@@ -1,7 +1,7 @@
1
- import { create } from '../create'
1
+ import { create } from '../src/create'
2
2
  import { waitFor } from '@testing-library/react'
3
3
  import { longPromise } from './test-utils'
4
- import { isPromise } from '../utils/is'
4
+ import { isPromise } from '../src/utils/is'
5
5
 
6
6
  describe('create', () => {
7
7
  it('should get basic value states here', async () => {
@@ -1,5 +1,5 @@
1
- import { create } from '../../create'
2
- import { AbortError } from '../common'
1
+ import { create } from '../src/create'
2
+ import { AbortError } from '../src/utils/common'
3
3
  import {
4
4
  isPromise,
5
5
  isFunction,
@@ -11,7 +11,7 @@ import {
11
11
  isUndefined,
12
12
  isState,
13
13
  isAbortError,
14
- } from '../is'
14
+ } from '../src/utils/is'
15
15
 
16
16
  describe('isPromise', () => {
17
17
  it('should return true for a Promise', () => {
@@ -1,5 +1,5 @@
1
1
  import { waitFor } from '@testing-library/react'
2
- import { createScheduler } from '../scheduler'
2
+ import { createScheduler } from '../src/scheduler'
3
3
 
4
4
  describe('scheduler', () => {
5
5
  it('should test scheduler by id', async () => {
@@ -1,5 +1,5 @@
1
- import { create } from '../create'
2
- import { select } from '../select'
1
+ import { create } from '../src/create'
2
+ import { select } from '../src/select'
3
3
  import { renderHook, waitFor } from '@testing-library/react'
4
4
  import { longPromise } from './test-utils'
5
5
  import { Suspense } from 'react'
@@ -211,8 +211,8 @@ describe('select', () => {
211
211
  await waitFor(() => {
212
212
  expect(result.current).toBe(false)
213
213
  expect(selectedState.get()).toBe(false)
214
- // re-render twice, as it hit suspense, because value is not resolved yet
215
- expect(render).toHaveBeenCalledTimes(2)
214
+ // re-render three times with React 19 suspense behavior
215
+ expect(render).toHaveBeenCalledTimes(3)
216
216
  })
217
217
 
218
218
  state.set(1)
@@ -221,7 +221,7 @@ describe('select', () => {
221
221
  expect(result.current).toBe(true)
222
222
  expect(selectedState.get()).toBe(true)
223
223
  // next time it re-render only once, as value is already resolved
224
- expect(render).toHaveBeenCalledTimes(3)
224
+ expect(render).toHaveBeenCalledTimes(4)
225
225
  })
226
226
  })
227
227
 
@@ -1,4 +1,4 @@
1
- import { shallow } from '../shallow'
1
+ import { shallow } from '../src/utils/shallow'
2
2
 
3
3
  describe('shallow', () => {
4
4
  it('should return true for identical primitive values', () => {
@@ -1,7 +1,7 @@
1
- import { renderHook, act } from '@testing-library/react-hooks'
1
+ import { renderHook, act } from '@testing-library/react'
2
2
  import { waitFor } from '@testing-library/react'
3
- import { create } from '../create'
4
- import { useValueLoadable } from '../use-value-loadable'
3
+ import { create } from '../src/create'
4
+ import { useValueLoadable } from '../src/use-value-loadable'
5
5
  import { longPromise } from './test-utils'
6
6
 
7
7
  describe('useValueLoadable', () => {
@@ -1,6 +1,6 @@
1
- import { renderHook, act } from '@testing-library/react-hooks'
2
- import { create } from '../create'
3
- import { useValue } from '../use-value'
1
+ import { renderHook, act } from '@testing-library/react'
2
+ import { create } from '../src/create'
3
+ import { useValue } from '../src/use-value'
4
4
  import { waitFor } from '@testing-library/react'
5
5
  import { longPromise } from './test-utils'
6
6
 
@@ -39,8 +39,8 @@ describe('useValue', () => {
39
39
  const state = create(() => {
40
40
  throw error
41
41
  })
42
- const { result } = renderHook(() => useValue(state))
43
- expect(result.error).toBe(error)
42
+ // In @testing-library/react, errors thrown in hooks propagate directly
43
+ expect(() => renderHook(() => useValue(state))).toThrow(error)
44
44
  })
45
45
 
46
46
  it('should handle promises returned from state suspense', async () => {
@@ -53,7 +53,7 @@ describe('useValue', () => {
53
53
  })
54
54
  await waitFor(() => {})
55
55
  expect(result.current).toBe(1)
56
- expect(renders).toHaveBeenCalledTimes(2)
56
+ expect(renders).toHaveBeenCalledTimes(3)
57
57
  })
58
58
 
59
59
  it('should unsubscribe on unmount', async () => {
@@ -92,8 +92,8 @@ describe('useValue', () => {
92
92
 
93
93
  await waitFor(() => {
94
94
  expect(result.current).toBe(0)
95
- // when it render, it will return a promise - hit the suspense, so it should be called twice
96
- expect(render).toHaveBeenCalledTimes(2)
95
+ // when it render, it will return a promise - hit the suspense, React 19 renders 3 times
96
+ expect(render).toHaveBeenCalledTimes(3)
97
97
  // after the promise resolved, it will re-render again, this part should be called once
98
98
  expect(renderAfter).toHaveBeenCalledTimes(1)
99
99
  })
package/build.ts ADDED
@@ -0,0 +1,67 @@
1
+ import esbuild from 'esbuild'
2
+ import path from 'path'
3
+ import fs from 'fs/promises'
4
+ import { exec } from 'child_process'
5
+ import { promisify } from 'util'
6
+
7
+ const execAsync = promisify(exec)
8
+
9
+ /**
10
+ * Recursively get all .ts files in a directory, excluding test files.
11
+ */
12
+ async function getAllFiles(dir: string): Promise<string[]> {
13
+ const dirents = await fs.readdir(dir, { withFileTypes: true })
14
+ const files = await Promise.all(
15
+ dirents.map((dirent) => {
16
+ const res = path.resolve(dir, dirent.name)
17
+ if (dirent.isDirectory()) {
18
+ if (dirent.name === '__tests__') return []
19
+ return getAllFiles(res)
20
+ }
21
+ return res.endsWith('.ts') || res.endsWith('.tsx') ? [res] : []
22
+ }),
23
+ )
24
+ return Array.prototype.concat(...files)
25
+ }
26
+
27
+ const entryDir = 'src'
28
+ const entry = path.join(entryDir, 'index.ts')
29
+ const outDir = 'dist'
30
+ const external = ['react', 'react-native', 'use-sync-external-store/shim/with-selector']
31
+
32
+ // Clean output directory
33
+ await fs.rm(outDir, { recursive: true, force: true })
34
+
35
+ // Ensure output directories
36
+ await fs.mkdir(path.join(outDir, 'cjs'), { recursive: true })
37
+ await fs.mkdir(path.join(outDir, 'esm'), { recursive: true })
38
+ await fs.mkdir(path.join(outDir, 'types'), { recursive: true })
39
+
40
+ // Get all source files
41
+ const files = await getAllFiles(entryDir)
42
+
43
+ // CommonJS build (single file)
44
+ await esbuild.build({
45
+ entryPoints: [entry],
46
+ bundle: true,
47
+ format: 'cjs',
48
+ outfile: path.join(outDir, 'cjs/index.js'),
49
+ minify: true,
50
+ preserveSymlinks: true,
51
+ external,
52
+ })
53
+
54
+ // ESM build (files as they are)
55
+ await esbuild.build({
56
+ entryPoints: files,
57
+ bundle: false,
58
+ format: 'esm',
59
+ outdir: path.join(outDir, 'esm'),
60
+ minify: true,
61
+ preserveSymlinks: true,
62
+ })
63
+
64
+ // TypeScript types generation
65
+ await execAsync('bunx tsc --project tsconfig.build.json')
66
+
67
+ console.log('Build complete: dist/')
@@ -0,0 +1,14 @@
1
+ "use strict";var Ae=Object.create;var O=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var se=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Re=(e,t)=>{for(var r in t)O(e,r,{get:t[r],enumerable:!0})},ae=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ie(t))!Oe.call(e,n)&&n!==r&&O(e,n,{get:()=>t[n],enumerable:!(o=_e(t,n))||o.enumerable});return e};var De=(e,t,r)=>(r=e!=null?Ae(Le(e)):{},ae(t||!e||!e.__esModule?O(r,"default",{value:e,enumerable:!0}):r,e)),qe=e=>ae(O({},"__esModule",{value:!0}),e);var Se=se(l=>{"use strict";function B(e,t){var r=e.length;e.push(t);e:for(;0<r;){var o=r-1>>>1,n=e[o];if(0<G(n,t))e[o]=t,e[r]=n,r=o;else break e}}function S(e){return e.length===0?null:e[0]}function M(e){if(e.length===0)return null;var t=e[0],r=e.pop();if(r!==t){e[0]=r;e:for(var o=0,n=e.length,a=n>>>1;o<a;){var c=2*(o+1)-1,s=e[c],i=c+1,u=e[i];if(0>G(s,r))i<n&&0>G(u,s)?(e[o]=u,e[i]=r,o=i):(e[o]=s,e[c]=r,o=c);else if(i<n&&0>G(u,r))e[o]=u,e[i]=r,o=i;else break e}}return t}function G(e,t){var r=e.sortIndex-t.sortIndex;return r!==0?r:e.id-t.id}l.unstable_now=void 0;typeof performance=="object"&&typeof performance.now=="function"?(ie=performance,l.unstable_now=function(){return ie.now()}):(J=Date,ue=J.now(),l.unstable_now=function(){return J.now()-ue});var ie,J,ue,b=[],h=[],Ue=1,T=null,f=3,ee=!1,A=!1,_=!1,te=!1,fe=typeof setTimeout=="function"?setTimeout:null,de=typeof clearTimeout=="function"?clearTimeout:null,ce=typeof setImmediate<"u"?setImmediate:null;function U(e){for(var t=S(h);t!==null;){if(t.callback===null)M(h);else if(t.startTime<=e)M(h),t.sortIndex=t.expirationTime,B(b,t);else break;t=S(h)}}function re(e){if(_=!1,U(e),!A)if(S(b)!==null)A=!0,x||(x=!0,k());else{var t=S(h);t!==null&&ne(re,t.startTime-e)}}var x=!1,I=-1,me=5,Te=-1;function pe(){return te?!0:!(l.unstable_now()-Te<me)}function X(){if(te=!1,x){var e=l.unstable_now();Te=e;var t=!0;try{e:{A=!1,_&&(_=!1,de(I),I=-1),ee=!0;var r=f;try{t:{for(U(e),T=S(b);T!==null&&!(T.expirationTime>e&&pe());){var o=T.callback;if(typeof o=="function"){T.callback=null,f=T.priorityLevel;var n=o(T.expirationTime<=e);if(e=l.unstable_now(),typeof n=="function"){T.callback=n,U(e),t=!0;break t}T===S(b)&&M(b),U(e)}else M(b);T=S(b)}if(T!==null)t=!0;else{var a=S(h);a!==null&&ne(re,a.startTime-e),t=!1}}break e}finally{T=null,f=r,ee=!1}t=void 0}}finally{t?k():x=!1}}}var k;typeof ce=="function"?k=function(){ce(X)}:typeof MessageChannel<"u"?(Z=new MessageChannel,le=Z.port2,Z.port1.onmessage=X,k=function(){le.postMessage(null)}):k=function(){fe(X,0)};var Z,le;function ne(e,t){I=fe(function(){e(l.unstable_now())},t)}l.unstable_IdlePriority=5;l.unstable_ImmediatePriority=1;l.unstable_LowPriority=4;l.unstable_NormalPriority=3;l.unstable_Profiling=null;l.unstable_UserBlockingPriority=2;l.unstable_cancelCallback=function(e){e.callback=null};l.unstable_forceFrameRate=function(e){0>e||125<e?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):me=0<e?Math.floor(1e3/e):5};l.unstable_getCurrentPriorityLevel=function(){return f};l.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var r=f;f=t;try{return e()}finally{f=r}};l.unstable_requestPaint=function(){te=!0};l.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var r=f;f=e;try{return t()}finally{f=r}};l.unstable_scheduleCallback=function(e,t,r){var o=l.unstable_now();switch(typeof r=="object"&&r!==null?(r=r.delay,r=typeof r=="number"&&0<r?o+r:o):r=o,e){case 1:var n=-1;break;case 2:n=250;break;case 5:n=1073741823;break;case 4:n=1e4;break;default:n=5e3}return n=r+n,e={id:Ue++,callback:t,priorityLevel:e,startTime:r,expirationTime:n,sortIndex:-1},r>o?(e.sortIndex=r,B(h,e),S(b)===null&&e===S(h)&&(_?(de(I),I=-1):_=!0,ne(re,r-o))):(e.sortIndex=n,B(b,e),A||ee||(A=!0,x||(x=!0,k()))),e};l.unstable_shouldYield=pe;l.unstable_wrapCallback=function(e){var t=f;return function(){var r=f;f=t;try{return e.apply(this,arguments)}finally{f=r}}}});var ye=se((Je,be)=>{"use strict";be.exports=Se()});var je={};Re(je,{EMPTY_SELECTOR:()=>V,STATE_SCHEDULER:()=>v,create:()=>xe,getId:()=>Y,isAbortError:()=>$,isArray:()=>N,isEqualBase:()=>E,isError:()=>C,isFunction:()=>P,isMap:()=>D,isPromise:()=>d,isSet:()=>q,isSetValueFunction:()=>W,isState:()=>Ge,isUndefined:()=>p,select:()=>j,shallow:()=>Pe,useValue:()=>H,useValueLoadable:()=>ge});module.exports=qe(je);var w=class extends Error{static Error="AbortError"};function Ne(e,t){t&&t.abort();let r=new AbortController,{signal:o}=r;return{promise:new Promise((a,c)=>{o.addEventListener("abort",()=>{c(new w)}),e.then(a).catch(c)}),controller:r}}function R(e,t=E){if(!p(e.current)){if(!p(e.previous)&&t(e.current,e.previous))return!1;e.previous=e.current}return!0}function y(e,t){let{cache:r,emitter:{emit:o}}=e;if(!d(t))return t;r.abortController&&r.abortController.abort();let{promise:n,controller:a}=Ne(t,r.abortController);return r.abortController=a,n.then(c=>{r.current=c,o()}).catch(c=>{$(c)||(r.current=c,o())})}function d(e){return e instanceof Promise}function P(e){return typeof e=="function"}function D(e){return e instanceof Map}function q(e){return e instanceof Set}function N(e){return Array.isArray(e)}function E(e,t){return e===t?!0:!!Object.is(e,t)}function W(e){return typeof e=="function"}function $(e){return e instanceof w}function C(e){return e instanceof Error}function p(e){return e===void 0}function Ge(e){return P(e)&&"get"in e&&"set"in e&&"isSet"in e&&e.isSet===!0}var V=e=>e;var F=De(ye()),Me=typeof process<"u"&&globalThis.IS_REACT_ACT_ENVIRONMENT!==void 0;function Fe(e){Me?queueMicrotask(e):(0,F.unstable_scheduleCallback)(F.unstable_NormalPriority,e)}function he(){let e=new Map,t=new Map,r=!1;function o(){let n=new Map(t);t.clear(),r=!1;for(let[a,c]of n){let s=e.get(a);if(s){for(let i of c)s.onResolveItem?.(i);s.onScheduleDone(c)}}}return{add(n,a){return e.set(n,a),()=>{e.delete(n)}},schedule(n,a){let c=t.get(n)??[];c.push(a),t.set(n,c),r||(r=!0,Fe(o))}}}function j(e,t,r){function o(){let u=!1,m=e.map(Q=>{let L=Q.get();return d(L)&&(u=!0),L});return u?new Promise((Q,L)=>{Promise.all(m).then(oe=>{if(oe.some(Ve=>p(Ve)))return L(new w);let Ce=t(...oe);Q(Ce)})}):t(...m)}function n(){if(p(s.cache.current)){let u=o();s.cache.current=y(s,u)}return s.cache.current}function a(){if(p(s.cache.current)){let m=o();s.cache.current=y(s,m)}let{current:u}=s.cache;return d(u)?new Promise(m=>{u.then(g=>{if(p(g)){m(a());return}m(g)})}):s.cache.current}let c=[];for(let u of e){let m=u.emitter.subscribe(()=>{v.schedule(s.id,null)});c.push(m)}let s=z({destroy(){for(let u of c)u();i(),s.emitter.clear(),s.cache.current=void 0},get:a,getSnapshot:n}),i=v.add(s.id,{onScheduleDone(){let u=o();s.cache.current=y(s,u),R(s.cache,r)&&(s.emitter.emit(),s.stateName??`${s.id}`,s.cache.current,void 0)}});return s}var we=require("react");var Ee=require("use-sync-external-store/shim/with-selector");function H(e,t=V){let{emitter:r}=e,o=(0,Ee.useSyncExternalStoreWithSelector)(e.emitter.subscribe,r.getSnapshot,r.getInitialSnapshot,t);if((0,we.useDebugValue)(o),d(o)||C(o))throw o;return o}function ve(e,t){let r=new Set,o=[];return{clear:()=>{for(let n of o)n();r.clear()},subscribe:n=>(r.add(n),()=>{r.delete(n)}),emit:(...n)=>{for(let a of r)a(...n)},contains:n=>r.has(n),getSnapshot:e,getInitialSnapshot:t,getSize:()=>r.size,subscribeToOtherEmitter(n){let a=n.subscribe(()=>{this.emit()});o.push(a)}}}var ke=0;function Y(){return ke++,ke.toString(36)}function z(e){let{get:t,destroy:r,set:o,getSnapshot:n}=e,a=!!o,c={},s=function(i){return H(s,i)};return s.isSet=a,s.id=Y(),s.emitter=ve(n),s.destroy=r,s.listen=function(i){return this.emitter.subscribe(()=>{let u=t();d(u)||i(t())})},s.withName=function(i){return this.stateName=i,this},s.select=function(i,u=E){return j([s],i,u)},s.get=t,s.set=o,s.cache=c,s}var v=he();function xe(e,t=E){function r(){try{if(p(a.cache.current)){let s=P(e)?e():e,i=y(a,s);return a.cache.current=i,a.cache.current}return a.cache.current}catch(s){a.cache.current=s}return a.cache.current}async function o(s,i){await s;let u=i(a.cache.current),m=y(a,u);a.cache.current=m}function n(s){let i=r(),u=W(s);if(u&&d(i)){o(i,s);return}a.cache.abortController&&a.cache.abortController.abort();let m=u?s(i):s,g=y(a,m);a.cache.current=g}let a=z({get:r,destroy(){r(),c(),a.emitter.clear(),a.cache.current=void 0},set(s){v.schedule(a.id,s)},getSnapshot:r}),c=v.add(a.id,{onScheduleDone(){a.cache.current=r(),R(a.cache,t)&&(a.emitter.emit(),a.stateName??`${a.id}`,a.cache.current,void 0)},onResolveItem:n});return P(e)||r(),a}var K=require("react");function ge(e,t=V){let{emitter:r}=e,o=(0,K.useSyncExternalStore)(r.subscribe,r.getSnapshot,r.getInitialSnapshot);return(0,K.useDebugValue)(o),d(o)?[void 0,!0,!1,void 0]:C(o)?[void 0,!1,!0,o]:[t(o),!1,!1,void 0]}function Pe(e,t){if(e==t)return!0;if(typeof e!="object"||e==null||typeof t!="object"||t==null)return!1;if(D(e)&&D(t)){if(e.size!==t.size)return!1;for(let[n,a]of e)if(!Object.is(a,t.get(n)))return!1;return!0}if(q(e)&&q(t)){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(N(e)&&N(t)){if(e.length!==t.length)return!1;for(let[n,a]of e.entries())if(!Object.is(a,t[n]))return!1;return!0}let r=Object.keys(e),o=Object.keys(t);if(r.length!==o.length)return!1;for(let n of r)if(!Object.prototype.hasOwnProperty.call(t,n)||!Object.is(e[n],t[n]))return!1;return!0}
2
+ /*! Bundled license information:
3
+
4
+ scheduler/cjs/scheduler.production.js:
5
+ (**
6
+ * @license React
7
+ * scheduler.production.js
8
+ *
9
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
10
+ *
11
+ * This source code is licensed under the MIT license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ *)
14
+ */
@@ -0,0 +1 @@
1
+ import{canUpdate as S,handleAsyncUpdate as s}from"./utils/common";import{isEqualBase as T,isFunction as u,isPromise as p,isSetValueFunction as V,isUndefined as y}from"./utils/is";import{createScheduler as E}from"./scheduler";import{sendToDevtools as b}from"./debug/development-tools";import{createState as v}from"./create-state";const i=E();function U(a,l=T){function c(){try{if(y(e.cache.current)){const t=u(a)?a():a,r=s(e,t);return e.cache.current=r,e.cache.current}return e.cache.current}catch(t){e.cache.current=t}return e.cache.current}async function d(t,r){await t;const n=r(e.cache.current),o=s(e,n);e.cache.current=o}function h(t){const r=c(),n=V(t);if(n&&p(r)){d(r,t);return}e.cache.abortController&&e.cache.abortController.abort();const o=n?t(r):t,f=s(e,o);e.cache.current=f}const e=v({get:c,destroy(){c(),m(),e.emitter.clear(),e.cache.current=void 0},set(t){i.schedule(e.id,t)},getSnapshot:c}),m=i.add(e.id,{onScheduleDone(){e.cache.current=c(),S(e.cache,l)&&(e.emitter.emit(),b({name:e.stateName??`state(${e.id})`,type:"state",value:e.cache.current,message:"update"}))},onResolveItem:h});return u(a)||c(),e}export{i as STATE_SCHEDULER,U as create};
@@ -0,0 +1 @@
1
+ const e=globalThis?.__REDUX_DEVTOOLS_EXTENSION__?.connect({name:"CustomState",trace:!0});e&&e.init({message:"Initial state"});function a(t){}export{a as sendToDevtools};
@@ -0,0 +1 @@
1
+ export*from"./utils/is";export*from"./types";import{create as p,STATE_SCHEDULER as a}from"./create";import{select as l}from"./select";import{useValue as x}from"./use-value";import{useValueLoadable as u}from"./use-value-loadable";import{shallow as E}from"./utils/shallow";import{getId as b}from"./utils/id";export{a as STATE_SCHEDULER,p as create,b as getId,l as select,E as shallow,x as useValue,u as useValueLoadable};
@@ -0,0 +1 @@
1
+ import{unstable_scheduleCallback as i,unstable_NormalPriority as r}from"scheduler";const a=typeof process<"u"&&globalThis.IS_REACT_ACT_ENVIRONMENT!==void 0;function h(n){a?queueMicrotask(n):i(r,n)}function S(){const n=new Map,t=new Map;let d=!1;function u(){const e=new Map(t);t.clear(),d=!1;for(const[o,s]of e){const l=n.get(o);if(l){for(const c of s)l.onResolveItem?.(c);l.onScheduleDone(s)}}}return{add(e,o){return n.set(e,o),()=>{n.delete(e)}},schedule(e,o){const s=t.get(e)??[];s.push(o),t.set(e,s),d||(d=!0,h(u))}}}export{S as createScheduler};
@@ -0,0 +1 @@
1
+ import{STATE_SCHEDULER as p}from"./create";import{createState as k}from"./create-state";import{sendToDevtools as E}from"./debug/development-tools";import{AbortError as g,canUpdate as v,handleAsyncUpdate as s}from"./utils/common";import{isPromise as h,isUndefined as c}from"./utils/is";function K(i,d,T){function a(){let t=!1;const n=i.map(u=>{const r=u.get();return h(r)&&(t=!0),r});return t?new Promise((u,r)=>{Promise.all(n).then(m=>{if(m.some(A=>c(A)))return r(new g);const w=d(...m);u(w)})}):d(...n)}function y(){if(c(e.cache.current)){const t=a();e.cache.current=s(e,t)}return e.cache.current}function f(){if(c(e.cache.current)){const n=a();e.cache.current=s(e,n)}const{current:t}=e.cache;return h(t)?new Promise(n=>{t.then(o=>{if(c(o)){n(f());return}n(o)})}):e.cache.current}const l=[];for(const t of i){const n=t.emitter.subscribe(()=>{p.schedule(e.id,null)});l.push(n)}const e=k({destroy(){for(const t of l)t();S(),e.emitter.clear(),e.cache.current=void 0},get:f,getSnapshot:y}),S=p.add(e.id,{onScheduleDone(){const t=a();e.cache.current=s(e,t),v(e.cache,T)&&(e.emitter.emit(),E({name:e.stateName??`derived(${e.id})`,type:"derived",value:e.cache.current,message:"update"}))}});return e}export{K as select};
@@ -13,3 +13,4 @@ type FullState<T> = GetStateOptions<T>['set'] extends undefined ? GetState<T> :
13
13
  */
14
14
  export declare function createState<T>(options: GetStateOptions<T>): FullState<T>;
15
15
  export {};
16
+ //# sourceMappingURL=create-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-state.d.ts","sourceRoot":"","sources":["../../src/create-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AAM/D,UAAU,eAAe,CAAC,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;CAC9B;AAED,KAAK,SAAS,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AACxF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAiCxE"}
@@ -1,8 +1,5 @@
1
1
  import type { DefaultValue, IsEqual, State } from './types';
2
- export declare const STATE_SCHEDULER: {
3
- add<T>(id: string | number | symbol, option: import("./scheduler").SchedulerOptions<T>): () => void;
4
- schedule<T>(id: string | number | symbol, value: T): void;
5
- };
2
+ export declare const STATE_SCHEDULER: import("./scheduler").Scheduler;
6
3
  /**
7
4
  * Create a new state with an initial value and optional equality check
8
5
  * @param initialValue The initial value or a function that returns the initial value
@@ -10,3 +7,4 @@ export declare const STATE_SCHEDULER: {
10
7
  * @returns A State<T> object
11
8
  */
12
9
  export declare function create<T>(initialValue: DefaultValue<T>, isEqual?: IsEqual<T>): State<T>;
10
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/create.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAwB,KAAK,EAAE,MAAM,SAAS,CAAA;AAKjF,eAAO,MAAM,eAAe,iCAAoB,CAAA;AAEhD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,OAAO,CAAC,CAAC,CAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CA2FpG"}
@@ -0,0 +1,13 @@
1
+ interface SendOptions {
2
+ message?: string;
3
+ type: string;
4
+ value: unknown;
5
+ name: string;
6
+ }
7
+ /**
8
+ * Send state information to Redux DevTools if available
9
+ * @param options Options containing message, type, value, and name
10
+ */
11
+ export declare function sendToDevtools(options: SendOptions): void;
12
+ export {};
13
+ //# sourceMappingURL=development-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"development-tools.d.ts","sourceRoot":"","sources":["../../../src/debug/development-tools.ts"],"names":[],"mappings":"AAWA,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACb;AACD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,QASlD"}
@@ -1,7 +1,9 @@
1
1
  export * from './utils/is';
2
2
  export * from './types';
3
- export { create } from './create';
3
+ export { create, STATE_SCHEDULER } from './create';
4
4
  export { select } from './select';
5
5
  export { useValue } from './use-value';
6
6
  export { useValueLoadable, type LoadableResult } from './use-value-loadable';
7
7
  export { shallow } from './utils/shallow';
8
+ export { getId } from './utils/id';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,25 @@
1
+ type ScheduleId = string | number | symbol;
2
+ /**
3
+ * Options for scheduler listeners
4
+ */
5
+ export interface SchedulerOptions<T> {
6
+ readonly onResolveItem?: (item: T) => void;
7
+ readonly onScheduleDone: (values?: T[]) => void;
8
+ }
9
+ /**
10
+ * Public interface for the scheduler
11
+ */
12
+ export interface Scheduler {
13
+ add: <T>(id: ScheduleId, options: SchedulerOptions<T>) => () => void;
14
+ schedule: <T>(id: ScheduleId, value: T) => void;
15
+ }
16
+ /**
17
+ * Create a new scheduler instance that batches state updates and flushes them together.
18
+ * Uses React's scheduler for priority-based scheduling in production,
19
+ * with queueMicrotask fallback for test environments.
20
+ * Only notifies states that have pending updates.
21
+ * @returns A scheduler with add and schedule methods
22
+ */
23
+ export declare function createScheduler(): Scheduler;
24
+ export {};
25
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/scheduler.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAE1C;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC1C,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,IAAI,CAAA;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAA;IACpE,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;CAChD;AAuBD;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,SAAS,CA0D3C"}
@@ -14,3 +14,4 @@ type AwaitedArray<T extends Array<unknown>> = {
14
14
  */
15
15
  export declare function select<T = unknown, S extends Array<unknown> = []>(states: StateDependencies<S>, selector: (...values: AwaitedArray<S>) => T, isEqual?: IsEqual<T>): GetState<T>;
16
16
  export {};
17
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAIhD,KAAK,iBAAiB,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,IAAI;KAChD,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;CACxC,CAAA;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,IAAI;KAC3C,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAA;AACD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAC/D,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC5B,QAAQ,EAAE,CAAC,GAAG,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,EAC3C,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GACnB,QAAQ,CAAC,CAAC,CAAC,CA+Gb"}
@@ -61,3 +61,4 @@ export interface State<T> extends GetState<T> {
61
61
  isSet: true;
62
62
  cache: Cache<T>;
63
63
  }
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAErD,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;AAC1D,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;AAC7D,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AACpD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAC3C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;AACtE,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,CAAA;IACX,QAAQ,CAAC,EAAE,CAAC,CAAA;IACZ,eAAe,CAAC,EAAE,eAAe,CAAA;CAClC;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,KAA8B,CAAC,CAAA;AAEjF,MAAM,WAAW,QAAQ,CAAC,CAAC,EAAE,aAAa,SAAS,OAAO,GAAG,KAAK;IAChE,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,SAAS,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACnF;;OAEG;IACH,GAAG,EAAE,MAAM,aAAa,SAAS,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACtD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACnB;;OAEG;IACH,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B;;;OAGG;IACH,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAA;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,CAAA;CAChI;AAED,MAAM,WAAW,KAAK,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAC3C;;;;OAIG;IACH,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAA;IACpC,KAAK,EAAE,IAAI,CAAA;IACX,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAChB"}
@@ -12,3 +12,4 @@ export type LoadableResult<T> = LoadableLoading | LoadableSuccess<T> | LoadableE
12
12
  */
13
13
  export declare function useValueLoadable<T, S = undefined>(state: GetState<T>, selector?: (stateValue: Awaited<T>) => S): LoadableResult<undefined extends S ? Awaited<T> : S>;
14
14
  export {};
15
+ //# sourceMappingURL=use-value-loadable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-value-loadable.d.ts","sourceRoot":"","sources":["../../src/use-value-loadable.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvD,KAAK,eAAe,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;AAC1D,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;AACtD,KAAK,aAAa,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AAEpD,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAA;AAEpF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAC/C,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,QAAQ,GAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAkB,GACvD,cAAc,CAAC,SAAS,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAkBtD"}
@@ -4,6 +4,7 @@ import { type GetState } from './types';
4
4
  * @param state The state to subscribe to
5
5
  * @param selector Optional function to derive a value from the state
6
6
  * @returns The current value of the state or the derived value from the selector
7
- * @throws If the value is a Promise or an Error, it will be thrown to be handled by an error boundary or suspense
7
+ * @throws {Promise | Error} If the value is a Promise or an Error, it will be thrown to be handled by an error boundary or suspense
8
8
  */
9
9
  export declare function useValue<T, S>(state: GetState<T>, selector?: (stateValue: Awaited<T>) => S): undefined extends S ? Awaited<T> : S;
10
+ //# sourceMappingURL=use-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-value.d.ts","sourceRoot":"","sources":["../../src/use-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,QAAQ,GAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAkB,GACvD,SAAS,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAkBtC"}
@@ -28,3 +28,4 @@ export declare function canUpdate<T>(cache: Cache<T>, isEqual?: IsEqual<T>): boo
28
28
  * @returns T or Promise<T>
29
29
  */
30
30
  export declare function handleAsyncUpdate<T>(state: State<T>, value: T): T;
31
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAGrD,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACnB,UAAU,CAAC,EAAE,eAAe,CAAA;CAC7B;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC,MAAM,CAAC,QAAQ,CAAC,KAAK,gBAAe;CACrC;AACD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,EAAE,eAAe,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAgBpH;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,OAAO,CAAC,CAAC,CAAe,GAAG,OAAO,CAQxF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA2BjE"}
@@ -19,3 +19,4 @@ export interface Emitter<T, P = undefined> {
19
19
  * @returns An emitter object with methods to manage listeners and emit events
20
20
  */
21
21
  export declare function createEmitter<T, P = undefined>(getSnapshot: () => T, getInitialSnapshot?: () => T): Emitter<T, P>;
22
+ //# sourceMappingURL=create-emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-emitter.d.ts","sourceRoot":"","sources":["../../../src/utils/create-emitter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,SAAS,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;AAChG,MAAM,WAAW,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS;IACvC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAC9B,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAA;IAC5D,WAAW,EAAE,MAAM,CAAC,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC,CAAA;IAC5B,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,CAAA;IAC9B,OAAO,EAAE,MAAM,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,KAAK,OAAO,CAAA;CAC1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAkCjH"}
@@ -3,3 +3,4 @@
3
3
  * @returns The unique state ID
4
4
  */
5
5
  export declare function getId(): string;
6
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../src/utils/id.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAG9B"}
@@ -11,3 +11,4 @@ export declare function isAbortError(value: unknown): value is AbortError;
11
11
  export declare function isError(value: unknown): value is Error;
12
12
  export declare function isUndefined(value: unknown): value is undefined;
13
13
  export declare function isState<T>(value: unknown): value is State<T>;
14
+ //# sourceMappingURL=is.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAEhG;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAEpE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAE3D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAE/D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAK5D;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAEhF;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAEtD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAE5D"}
@@ -6,3 +6,4 @@
6
6
  * @returns True if the values are shallowly equal, false otherwise.
7
7
  */
8
8
  export declare function shallow<T>(valueA: T, valueB: T): boolean;
9
+ //# sourceMappingURL=shallow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shallow.d.ts","sourceRoot":"","sources":["../../../src/utils/shallow.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAmDxD"}
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "muya",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "author": "samuel.gjabel@gmail.com",
5
5
  "repository": "https://github.com/samuelgjabel/muya",
6
- "main": "cjs/index.js",
7
- "module": "esm/index.js",
6
+ "main": "dist/cjs/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "typescript": {
10
+ "main": "src/index.ts"
11
+ },
12
+ "react-native": "src/index.ts",
8
13
  "description": "👀 Another React state management library",
9
14
  "homepage": "https://github.com/samuelgjabel/muya",
10
15
  "keywords": [
@@ -20,10 +25,28 @@
20
25
  ],
21
26
  "license": "MIT",
22
27
  "peerDependencies": {
23
- "react": ">=18 <20",
24
- "use-sync-external-store": ">=1.4.0 <1.6.0"
28
+ "react": ">=18 <20"
29
+ },
30
+ "dependencies": {
31
+ "scheduler": "^0.27.0",
32
+ "use-sync-external-store": "^1.6.0"
25
33
  },
26
- "react-native": "src/index.ts",
27
34
  "sideEffects": false,
28
- "types": "types/index.d.ts"
29
- }
35
+ "scripts": {
36
+ "build": "bun run build.ts",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint \"src/**/*.{ts,tsx}\" \"__tests__/**/*.{ts,tsx}\" --fix",
39
+ "test": "bun test ./__tests__",
40
+ "code-check": "bun run typecheck && bun run lint && bun run test"
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/types/index.d.ts",
45
+ "import": "./dist/esm/index.js",
46
+ "require": "./dist/cjs/index.js"
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@types/scheduler": "^0.26.0"
51
+ }
52
+ }
package/src/create.ts CHANGED
@@ -2,7 +2,7 @@ import { canUpdate, handleAsyncUpdate } from './utils/common'
2
2
  import { isEqualBase, isFunction, isPromise, isSetValueFunction, isUndefined } from './utils/is'
3
3
  import type { DefaultValue, IsEqual, SetStateCb, SetValue, State } from './types'
4
4
  import { createScheduler } from './scheduler'
5
- import { subscribeToDevelopmentTools } from './debug/development-tools'
5
+ import { sendToDevtools } from './debug/development-tools'
6
6
  import { createState } from './create-state'
7
7
 
8
8
  export const STATE_SCHEDULER = createScheduler()
@@ -89,6 +89,12 @@ export function create<T>(initialValue: DefaultValue<T>, isEqual: IsEqual<T> = i
89
89
  return
90
90
  }
91
91
  state.emitter.emit()
92
+ sendToDevtools({
93
+ name: state.stateName ?? `state(${state.id})`,
94
+ type: 'state',
95
+ value: state.cache.current,
96
+ message: 'update',
97
+ })
92
98
  },
93
99
  onResolveItem: setValue,
94
100
  })
@@ -97,6 +103,5 @@ export function create<T>(initialValue: DefaultValue<T>, isEqual: IsEqual<T> = i
97
103
  getValue()
98
104
  }
99
105
 
100
- subscribeToDevelopmentTools(state)
101
106
  return state
102
107
  }